When showing notifications on Android 11 having setFullScreenIntent
, action button in the notification gets an annoying border:
While running same code on Android 10 or when removing setFullScreenIntent
on Android 11, notification design will be material as intended:
My code for reference:
private void showNotification() {
NotificationManager androidNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
createHeadsUpNotificationChannel(androidNotificationManager);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.layout_sample_notif);
contentView.setTextViewText(R.id.id1, "Header");
contentView.setTextViewText(R.id.id2, "Body");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL);
builder.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentTitle("Sample Notification")
.setSmallIcon(R.drawable.sample_icon)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(contentView)
.setGroup(GROUP_KEY)
.setCategory(NotificationCompat.CATEGORY_ALARM).setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL);
Intent fullScreenIntent = new Intent(this, FullscreenActivity.class);
fullScreenIntent.setAction(String.valueOf(System.currentTimeMillis()));
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setFullScreenIntent(fullScreenPendingIntent, true);
Intent dismissIntent = new Intent(this, MyService.class);
dismissIntent.setAction("action_dismiss");
builder.setOngoing(true)
.addAction(R.drawable.sample_icon,
"Dismiss",
PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_ONE_SHOT));
androidNotificationManager.notify(0, builder.build());
}
private void createHeadsUpNotificationChannel(NotificationManager androidNotificationManager) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
"Sample Channel",
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Sample Desc");
channel.enableLights(false);
channel.enableVibration(false);
androidNotificationManager.createNotificationChannel(channel);
}
}
I need help having a consistent material design for my notification.
from Android notification setFullScreenIntent action button unwanted border on Android 11
No comments:
Post a Comment