Reputation: 2080
I want to show notification like this(on Android 7.0 API24):
But I got result with just tray icon not full content.(Android 8.1.0 API27) :
CODE:
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());
}
I don't know why it is working at lower api, but at higher api it is not working!
It seems like there is problem with NotificationChannel, but cannot get reason.
How to show full content of notification like above picture at over OREO api?
Upvotes: 0
Views: 248
Reputation: 19273
I don't see anything suspicious in your code, but there is a chance, that Android removed this feature (sneak peek of important notification) - don't know anything about that - or custom OEM producer redesigned it's UI considering this sneak peek as undesirable
Upvotes: 1