Ad

Android Notification Is Not Showing As A Message

- 1 answer

The notification it self is working good, but not as I want. It vibrates and shows the icon defined but not as a Watsapp Notification and in the setCategory I put CATEGORY_MESSAGE but still, nothing!

on my App class i put :

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID,CHANNEL_NAME,NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription(CHANNEL_DESC);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationManager manager = getSystemService(NotificationManager.class);
        assert manager != null;
        manager.createNotificationChannel(channel);
    }

Fragment :

private void T(String message){
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID)
            .setContentText(message)
            .setContentTitle("Test")
            .setColor(0xff123456)
            .setSmallIcon(R.drawable.com_facebook_button_icon)
            .setCategory(CATEGORY_MESSAGE)
            .setPriority(PRIORITY_HIGH);
    NotificationManagerCompat compat = NotificationManagerCompat.from(getApplicationContext());
    compat.notify(1,mBuilder.build());

}

This is How I want it to notify :

enter image description here

This is how is current notifying

enter image description here

I'm using the SDK 27

Ad

Answer

After discussing with OP in chat, here's my best explanation about what could have happened:

A notification channel can only be created once, after which it becomes immutable to the app. It can only be tweaked by the user through the Settings. If someone follows the examples in the official docs first, they might create the channel with IMPORTANCE_DEFAULT. After this, even if they change the code later, the channel will remain at level 'High: Make Sound' and not be set to 'Urgent: Make Sound and pop on screen' as desired. Docs on importance level


The code in the question is perfectly fine, and should create a channel with the 'Urgent' level when installed for the first time. In any case, uninstalling the app manually and then installing it again will recreate the channels, setting the level to whatever is mentioned in the latest code.

Ad
source: stackoverflow.com
Ad