Да, вы можете, но только локальное уведомление (не на базе Firebase или на сервере), и я понимаю, что если вы зададите этот вопрос, это будет вашим единственным требованием.
В моем случае я реализовал прослушиватель, который должен проверить событие. Если это отвечает моим требованиям, тогда я просто вызываю приведенную ниже функцию.
private void generateBigTextStyleNotification() {
String notificationChannelId =
NotificationUtil.createNotificationChannel(thisService);
String title = "Your title";
String msg = "Your message";
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
.bigText(msg)
.setBigContentTitle(title)
.setSummaryText("Your Summary");
PendingIntent notifyPendingIntent =
PendingIntent.getActivity(
thisService,
0,
new Intent(),
PendingIntent.FLAG_CANCEL_CURRENT
);
//Build and issue the notification.
// Notification Channel Id is ignored for Android pre O (26).
NotificationCompat.Builder notificationCompatBuilder =
new NotificationCompat.Builder(
thisService, notificationChannelId);
notificationCompatBuilder.setAutoCancel(true);
GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);
Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + thisService.getPackageName() + "YourSoundPath");
Notification notification = notificationCompatBuilder
// BIG_TEXT_STYLE sets title and content for API 16 (4.1 and after).
.setStyle(bigTextStyle)
// Title for API <16 (4.0 and below) devices.
.setContentTitle(title)
// Content for API <24 (7.0 and below) devices.
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setSound(alarmSound)
.setLargeIcon(BitmapFactory.decodeResource(
thisService.getResources(),
R.mipmap.ic_launcher))
.setContentIntent(notifyPendingIntent)
.setDefaults(NotificationCompat.FLAG_AUTO_CANCEL)
// Set primary color (important for Wear 2.0 Notifications).
.setColor(ContextCompat.getColor(thisService, R.color.secondary_background_color))
.setCategory(Notification.CATEGORY_EVENT)
// Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
// 'importance' which is set in the NotificationChannel. The integers representing
// 'priority' are different from 'importance', so make sure you don't mix them.
.setPriority(NotificationCompat.PRIORITY_MAX)
// Sets lock-screen visibility for 25 and below. For 26 and above, lock screen
// visibility is set in the NotificationChannel.
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setAutoCancel(true)
// Adds additional actions specified above.
.build();
mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);
}