import
android.app.Notification;
import
android.app.NotificationChannel;
import
android.app.NotificationManager;
import
android.content.Context;
import
android.os.Build;
import
androidx.core.app.NotificationCompat;
public
class
Example {
private
void
issueNotification()
{
if
(Build.VERSION.SDK_INT
>= Build.VERSION_CODES.O) {
makeNotificationChannel(
"CHANNEL_1"
,
"Example channel"
,
NotificationManager.IMPORTANCE_DEFAULT);
}
NotificationCompat.Builder notificationBuilder
=
new
NotificationCompat.Builder(
this
,
"CHANNEL_1"
);
notificationBuilder
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(
"Notification!"
)
.setContentText(
"This is an Oreo notification!"
)
.setNumber(
3
);
NotificationManager notificationManager
= (NotificationManager)getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.notify(
1
, notificationBuilder.build());
}
private
void
makeNotificationChannel(String channelId,
String channelName,
int
importance)
{
NotificationChannel channel
=
new
NotificationChannel(
channelId, channelName, importance);
NotificationManager notificationManager
= (NotificationManager)getSystemService(
NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(
channel);
}
}