Alert icons that are not inserted in Android O

With the Android developer previewing, Google introduced notification icons that should appear on the launch icon. I am using emulator with Android O from dev channel.I wrote a simple code to show the alert icon, but it does not work -

Notification notification = new Notification.Builder(getApplicationContext()) .chooseBadgeIcon(Notification.BADGE_ICON_SMALL) .setSmallIcon(android.R.drawable.btn_star) .setNumber(10) .build(); mNotificationManager.notify(1, notification); 

It just displays as a normal notification.

API - https://developer.android.com/reference/android/app/Notification.Builder.html#chooseBadgeIcon(int)

Has anyone worked on this? Did I miss something?

The icon is displayed in the settings.

enter image description here


Tried with NotificationChannel too. Does not work -

  NotificationChannel mChannel = new NotificationChannel("TestBadge_id", "TestBadgeName", NotificationManager.IMPORTANCE_HIGH); mChannel.enableLights(true); mChannel.setLightColor(Color.RED); mChannel.setShowBadge(true); mNotificationManager.createNotificationChannel(mChannel); Notification notification = new Notification.Builder(getApplicationContext()) .chooseBadgeIcon(Notification.BADGE_ICON_SMALL) .setSmallIcon(android.R.drawable.btn_star) .setNumber(10) .setChannel("TestBadge_id") .build(); mNotificationManager.notify(1, notification); 
+5
source share
1 answer

The Android-O notification icon examples do not seem to work in the emulator in earlier versions of the preview. But with the latest version of the Android-O developer preview-3 icons are displayed correctly, as described in Notification Icons .

To display the notification icon, you need to set setShowBadge (boolean) for the notification channel to true . The default icons will be displayed as follows:

Icon Sample

With a long press, if there is more than one notification, an account is displayed. The score is automatically increased / decreased based on active notifications. You can also set up an account manually using Notification.Builder.setNumber () .

An example showing the number of notifications when the launch icon is pressed for a long time:

Quantity Icon Notification

Make sure you configure the latest API:

 compileSdkVersion 26 buildToolsVersion "26.0.0" targetSdkVersion 26 

Tested in Android emulator version for Android 26.1.1 .

+3
source

Source: https://habr.com/ru/post/1266231/


All Articles