public static final CharSequence VERBOSE_NOTIFICATION_CHANNEL_NAME ="Verbose WorkManager Notifications";
public static String VERBOSE_NOTIFICATION_CHANNEL_DESCRIPTION ="Shows notifications whenever work starts";
public static final CharSequence NOTIFICATION_TITLE = "WorkRequest Starting";
public static final String CHANNEL_ID = "VERBOSE_NOTIFICATION" ;
public static final int NOTIFICATION_ID = 1;
static void makeStatusNotification(String message, Context context) {
// Make a channel if necessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = VERBOSE_NOTIFICATION_CHANNEL_NAME;
String description = VERBOSE_NOTIFICATION_CHANNEL_DESCRIPTION;
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Add the channel
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
// Create the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(NOTIFICATION_TITLE)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVibrate(new long[0]);
// Show the notification
NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, builder.build());
}