WorkManager doWork callback is not received in Redmi and other custom Chinese ROM when device got rebooted and force closed the app

一世执手 提交于 2019-12-21 06:17:04

问题


My app is not receiving push notification in Redmi phones while the app is in the background or it got killed by swiping.

So I am trying to wake the phone by WorkManager which works on many phones except Redmi and other Chinese custom ROM phones.

Here is my code of Worker class

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;
}

I am trying to enqueue the work through 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);

回答1:


Which version of WorkManager are you using ? We fixed a few bugs with respect to PeriodicWork and force-stopping of apps in alpha05. alpha06 is out, and I recommend you try using it. If you still have the same problem, please report back on the issue tracker with a reproducible test case on the issue tracker.




回答2:


<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

Add these permissions in your manifest file it may work.



来源:https://stackoverflow.com/questions/51655622/workmanager-dowork-callback-is-not-received-in-redmi-and-other-custom-chinese-ro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!