Я пытаюсь отправить уведомление через 15 минут с помощью WorkManager, но я не получил никаких уведомлений, вот мой код:
NotificationWorkManager. java
@NonNull
@Override
public Result doWork() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel("Channel", "Channel", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Your Way To God...");
NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
Notification notification = new NotificationCompat.Builder(getApplicationContext(),"Channel")
.setSmallIcon(R.drawable.app_icon)
.setContentTitle("Hello")
.setContentText("This is My Notification...")
.setPriority(NotificationCompat.PRIORITY_HIGH).build();
notificationManagerCompat.notify(1, notification);
return Result.success();
}
Дом. java
PeriodicWorkRequest showNotification =
new PeriodicWorkRequest.Builder(NotificationWorkManager.class, 15, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork("Notification", ExistingPeriodicWorkPolicy.KEEP, showNotification);