Button. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
String id="my_channel_01";
String name="I am channel name";
NotificationManager manager=(NotificationManager) getSystemService (NOTIFICATION_SERVICE);
The v (" MainActivity ", "12312");
Notification Notification=null;
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. O {
NotificationChannel mChannel=new NotificationChannel (id, name, NotificationManager. IMPORTANCE_LOW);
Toast. MakeText (MainActivity. This mChannel. The toString (), Toast. LENGTH_SHORT), show ();
Manager. CreateNotificationChannel (mChannel);
Notification=new notification. Builder (MainActivity. This null)
SetChannelId (id)
. SetContentTitle (" 5 new messages ")
. SetContentText (" hahaha ")
SetSmallIcon (R.m ipmap. Ic_launcher). The build ();
} else {
NotificationCompat. Builder notificationBuilder=new NotificationCompat. Builder (MainActivity. This null)
. SetContentTitle (" 5 new messages ")
. SetContentText (" hahaha ")
SetSmallIcon (R.m ipmap. Ic_launcher)
SetOngoing (true);
Notification=notificationBuilder. The build ();
}
Manager. Notify (111123, notification);
}
});
CodePudding user response:
NotificationManagerCompat. The from (this). AreNotificationsEnabled ();See if permissions
CodePudding user response:
8.0 the system, please click https://blog.csdn.net/qq_35749683/article/details/80451791