我的应用程序在后台运行时没有在 Redmi 手机中收到推送通知,或者它被刷卡杀死了。
所以我试图通过 WorkManager 唤醒手机,它适用于除 Redmi 和其他中国定制 ROM 手机之外的许多手机。
这是我的 Worker 类代码
public class OpenTalkWorkManager extends Worker {
@NonNull
@Override
public Result doWork() {
Log.i("wake_up", "Waking up now: " + System.currentTimeMillis());
FirebaseUtils.getInstance().updateUserPresenceStatus(getApplicationContext(), "yes");
Intent intent = new Intent("com.opentalk.WAKE_UP");
getApplicationContext().sendBroadcast(intent);
return Result.SUCCESS;
}
我正在尝试通过 PeriodicWorkRequest 将工作排入队列
PeriodicWorkRequest.Builder mPeriodicWorkRequest = new PeriodicWorkRequest.Builder(OpenTalkWorkManager.class, 4, TimeUnit.MINUTES);
Constraints myConstraints = new Constraints.Builder()
.setRequiresBatteryNotLow(false)
.setRequiredNetworkType(NetworkType.NOT_REQUIRED)
.setRequiresCharging(false)
.setRequiresDeviceIdle(false)
.setRequiresStorageNotLow(false)
// Many other constraints are available, see the
// Constraints.Builder reference
.build();
PeriodicWorkRequest myWork = mPeriodicWorkRequest.setConstraints(myConstraints).build();
UUID compressionWorkId = myWork.getId();
WorkManager.getInstance().cancelWorkById(compressionWorkId);
WorkManager.getInstance().enqueue(myWork);