简体   繁体   中英

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. 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

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. see your OS on phone u used allows it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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