Notificationで表示されない問題の解決Android 8.0をサポート
1328 ワード
anddroidを使って通知する時に現れて、明らかにコードは間違いなくて、しかし通知は現れていないで、携帯電話を交換した後に現れて、調べた後に、androidバージョンの問題のためであることを発見して、今android 8.0のバージョンのコードに適してどのようですか.
tring id = "my_channel_01";
String name=" ";
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
Toast.makeText(this, mChannel.toString(), Toast.LENGTH_SHORT).show();
Log.i(TAG, mChannel.toString());
notificationManager.createNotificationChannel(mChannel);
notification = new Notification.Builder(this)
.setChannelId(id)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher).build();
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.setChannel(id);//
notification = notificationBuilder.build();
}
notificationManager.notify(111123, notification);