如何在Android Oreo及以上版本的通知托盘中显示带有图片的Android通知?
我想在Android 7.0 API24上显示如下通知: 但我得到的结果只是托盘图标而不是全部内容。Android 8.1.0 API27: 代码: 我不知道为什么它在较低的api下工作,但在较高的api下它不工作 NotificationChannel似乎有问题,但无法找到原因如何在Android Oreo及以上版本的通知托盘中显示带有图片的Android通知?,android,notifications,Android,Notifications,我想在Android 7.0 API24上显示如下通知: 但我得到的结果只是托盘图标而不是全部内容。Android 8.1.0 API27: 代码: 我不知道为什么它在较低的api下工作,但在较高的api下它不工作 NotificationChannel似乎有问题,但无法找到原因 如何在over OREO api上显示如上图所示的通知的完整内容?我在您的代码中没有发现任何可疑之处,但有可能,Android删除了重要通知的偷窥功能——对此一无所知——或者定制OEM生产商重新设计了它的UI,认为这
如何在over OREO api上显示如上图所示的通知的完整内容?我在您的代码中没有发现任何可疑之处,但有可能,Android删除了重要通知的偷窥功能——对此一无所知——或者定制OEM生产商重新设计了它的UI,认为这种偷窥是不可取的
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String channelID="channelID";
String channelName = "channelName";
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder;
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// Android 8.1.0 API27
NotificationChannel notificationChannel = new NotificationChannel(channelID, channelName, notificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), channelID);
notificationBuilder
.setSmallIcon(R.drawable.ic_add_post)
.setContentTitle("some title")
.setContentText("some message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[]{1000, 1000})
.setLights(Color.BLUE, 1,1)
.setShowWhen(true)
.setContentIntent(notifyPendingIntent);
notificationManager.notify("do_not1",0 /* ID of notification */, notificationBuilder.build());
} else {
notificationBuilder = new NotificationCompat.Builder(getApplicationContext());
notificationBuilder
.setSmallIcon(R.drawable.ic_add_post)
.setContentTitle("some title")
.setContentText("some message")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[]{1000, 1000})
.setLights(Color.BLUE, 1,1)
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setContentIntent(notifyPendingIntent);
notificationManager.notify("do_not1",0 /* ID of notification */, notificationBuilder.build());
}