Skip to content

Commit

Permalink
[Android 12+] remove content from collapsed state of notification
Browse files Browse the repository at this point in the history
height restrictions for custom notifications on Android 12+:
*  48dp: collapsed state
*  88dp: heads up
* 252dp: expanded state

height of custom notification:
*  64dp

see:
* https://developer.android.com/about/versions/12/behavior-changes-12#custom-notifications
  https://developer.android.com/develop/ui/views/notifications/custom-notification
  • Loading branch information
warren-bank committed Jan 24, 2023
1 parent e3b887a commit 00da090
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ private Notification getNotification() {
if (Build.VERSION.SDK_INT >= 26) {
Notification.Builder builder = new Notification.Builder(/* context= */ NetworkingService.this, /* channelId= */ getNotificationChannelId());

if (Build.VERSION.SDK_INT >= 31)
if (Build.VERSION.SDK_INT >= 31) {
builder.setContentTitle(getNetworkAddress());
builder.setContentText(getString(R.string.notification_service_content_line3));
builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE);
}

notification = builder.build();
}
Expand Down Expand Up @@ -284,7 +287,13 @@ private Notification getNotification() {
contentView.setTextViewText(R.id.notification_text_line1, getString(R.string.notification_service_content_line1));
contentView.setTextViewText(R.id.notification_text_line2, getNetworkAddress());
contentView.setTextViewText(R.id.notification_text_line3, getString(R.string.notification_service_content_line3));
notification.contentView = contentView;

if (Build.VERSION.SDK_INT < 31)
notification.contentView = contentView;
if (Build.VERSION.SDK_INT >= 16)
notification.bigContentView = contentView;
if (Build.VERSION.SDK_INT >= 21)
notification.headsUpContentView = contentView;

return notification;
}
Expand Down

0 comments on commit 00da090

Please sign in to comment.