08.1 Notifications
08.1 Notifications
Alarms and
Schedulers
Lesson 8
■ Small icon
■ Title
■ Detail text
setPriority(NotificationCompat.PRIORITY_HIGH)
This work is licensed under a
Android Developer Notifications Creative Commons Attribution 4.0 15
Fundamentals V2 International License
Importance level and priority
constants Importance
Priority (Android
User-visible importance level (Android 8.0 and
7.1 and lower)
higher)
Urgent
PRIORITY_HIGH or
Makes a sound and appears as a heads- IMPORTANCE_HIGH
PRIORITY_MAX
up notification
High
IMPORTANCE_DEFAUL PRIORITY_DEFAULT
Makes a sound T
Medium
IMPORTANCE_LOW PRIORITY_LOW
No sound
Low
No sound and doesn't appear in the IMPORTANCE_MIN PRIORITY_MIN
status bar
This work is licensed under a
Android Developer Notifications Creative Commons Attribution 4.0 16
Fundamentals V2 International License
Creating
Notifications
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.android_icon)
.setContentTitle("You've been notified!")
.setContentText("This is your notification
text.");
Intent notificationIntent =
new Intent(this, MainActivity.class);
PendingIntent notificationPendingIntent =
PendingIntent.getActivity(
this,
NOTIFICATION_ID,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
This work is licensed under a
Android Developer Notifications Creative Commons Attribution 4.0 28
Fundamentals V2 International License
Step 3: Add to notification
builder
To set tap action to the notification:
.setContentIntent(notificationPendingIntent);
.addAction(R.drawable.ic_color_lens_black_24d
p,
"R.string.label",
notificationPendingIntent);
This work is licensed under a
Android Developer Notifications Creative Commons Attribution 4.0 30
Fundamentals V2 International License
Expanded
view
notificatio
ns
mNotifyManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
mNotifyManager.notify(NOTIFICATION_ID, myNotification);