Oreo Notification Bar Round Icon

I want to know how I can change the small notification bar icon in android Oreo (API 26). It has a round white icon displayed in the notification panel. How can I change it? Manifest file icon notification icon as shown below.

<meta-data
     android:name="com.google.firebase.messaging.default_notification_icon"
     android:resource="@drawable/ic_status" />

See image below.

Screenshot

+4
source share
2 answers
  • Remove tag <meta-data>from AndroidManifest.xml.
  • The notification constructor has .setSmallIcon(int icon, int level)one that takes an icon as a required argument and a level parameter as an optional argument.

NOTE. .setSmallIcon accepts blueprints and does NOT accept mipmaps .

Android 8.0 Oreo Notification Channels :

public class MainActivity extends AppCompatActivity {

    private CharSequence name;
    private int notifyId;
    private int importance;
    private String id;
    private String description;

    private Notification mNotification;
    private NotificationManager mNotificationManager;
    private NotificationChannel mChannel;
    private PendingIntent mPendingIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        binding.btnNotification.setOnClickListener(v -> notification());
    }

    private void notification() {

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notifyId = 1;
        description = "Hello World, welcome to Android Oreo!";

        Intent intent = new Intent(this, MainActivity.class);
        mPendingIntent = PendingIntent.getActivity(this, notifyId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        if (SDK_INT >= O) {
            id = "id";
            name = "a";
            importance = NotificationManager.IMPORTANCE_HIGH;

            mChannel = new NotificationChannel(id, name, importance);
            mChannel.setDescription(description);
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.WHITE);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[] {100, 300, 200, 300});
            mNotificationManager.createNotificationChannel(mChannel);

            mNotification = new Notification.Builder(MainActivity.this, id)
                .setContentTitle(id)
                .setContentText(description)
                .setContentIntent(mPendingIntent)
                .setSmallIcon(R.drawable.ic_launcher_foreground)
                .build();
        } else {
            mNotification = new Notification.Builder(MainActivity.this)
                .setContentTitle(id)
                .setContentText(description)
                .setContentIntent(mPendingIntent)
                .setSmallIcon(R.drawable.ic_launcher_foreground)
                .setLights(Color.WHITE, Color.RED, Color.GREEN)
                .setVibrate(new long[] {100, 300, 200, 300})
                .build();
        }
            mNotificationManager.notify(notifyId, mNotification);
    }
}
-2

Firebase SDK 11.8.0 Android 8.0 (API 26) , .

screenshot 1

getResources().

, , HTTP POST request :

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
   "to": "/topics/test",
   "data": {
       "title": "Update",
       "body": "New feature available"
    }
 }

FirebaseMessagingService, :

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent i = new Intent(context, HomeActivity.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0, i, 
                                         PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = 
            new NotificationCompat.Builder(this, GENERAL_CHANNEL_ID)
                 .setSmallIcon(R.drawable.ic_stat_chameleon)
                 .setContentTitle(remoteMessage.getData().get("title"))
                 .setContentText(remoteMessage.getData().get("body"))
                 .setContentIntent(pi);

        NotificationManager manager = 
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, builder.build());
    }
}

, , Android 8.0:

screenshot 2

+1

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


All Articles