[英]Notification not triggered after 3 days in work manager android
我試圖在 3 天后通過WorkManager
安排通知,但它沒有被觸發。 我嘗試了以下方法。
文章通知工作者
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 請求如下
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();
如果您能幫我解決這個問題,我將不勝感激。
我記得有一次我使用 WorkManager 來安排一個服務,但是當應用程序關閉時它沒有觸發它原來是因為我在小米手機上測試它。 在您使用的手機上查看您的操作系統允許它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.