简体   繁体   English

在工作管理器 android 中 3 天后未触发通知

[英]Notification not triggered after 3 days in work manager android

I was trying to schedule notification after 3 days via WorkManager but it does not get triggered.我试图在 3 天后通过WorkManager安排通知,但它没有被触发。 I have tried the following.我尝试了以下方法。

ArticleNotificationWorker文章通知工作者

public class ArticleNotificationWorker extends Worker {

    private static final String WORK_RESULT = "work_result";
    Context mContext;
    public static final String FROM_ARTICLE_NOTIFICATIONS = "ArticleNotifications";


    public ArticleNotificationWorker(
            @NonNull Context context,
            @NonNull WorkerParameters params) {
        super(context, params);
        mContext = context;


    }



    @NonNull
    @Override
    public Result doWork() {
        //create notifications only after three days of unlocking the article
        buildAndSendNotification();
        Data outputData = new Data.Builder().putString(WORK_RESULT, "Jobs Finished").build();
        return Result.success(outputData);

    }

    private void buildAndSendNotification(){
       //send notification
    }



}

WorkManager request goes as follows WorkManager 请求如下

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(ArticleNotificationWorker.class)
                .setInitialDelay(3, TimeUnit.DAYS)
                .addTag(IAppConstants.ARTICLE_NOTIFICATION)
                .build();

        workManager.beginUniqueWork(IAppConstants.ARTICLE_NOTIFICATION_WORK, ExistingWorkPolicy.REPLACE,
                request)
                .enqueue();

I would really appreciate if you could help me with the issue.如果您能帮我解决这个问题,我将不胜感激。

I remember once I used WorkManager to schedule an service but it wasn't triggering it when app was closed turned out it was because of I was testing it on mi phone.我记得有一次我使用 WorkManager 来安排一个服务,但是当应用程序关闭时它没有触发它原来是因为我在小米手机上测试它。 see your OS on phone u used allows it.在您使用的手机上查看您的操作系统允许它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM