Change the default icon of NotificationCompat.Builder Android

1

I want to change the notification icon that appears by default.

I have my NotificationCompat.Builder as well:

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.largeicon);
NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.smallicon)
                    .setLargeIcon(largeIcon)
                    .setColor(0x00)
                    .setContentTitle("B-TRAKER")
                    .setOngoing(true)
                    .setContentText("Abrir aplicación");

The fact is that it is not changed by the icon that I have established. Researching a bit I saw that to show the icons I must change the targetSdkVersion of the Gradle to 20, but still does not show me the icon I want. It only shows the default Android icon (the android).

Edit: Well, apparently my code was fine, I rebooted the device and now if you take the icons.

    
asked by Juan Alberto Carrasco Galán 24.05.2017 в 20:07
source

2 answers

1

The images you upload are not the default images, the default images are within the /mipmap / directory and are called ic_launcher.png and your notification would look like this:

The known problem in Android 5.0 is that your notifications are seen in this way and it is related to that it is not an image with transparency, apparently they already deleted this information from the documentation .

But if the problem is that the image is not displayed, it may be that in some folder there is no image of the required density.

res/
    drawable/   
        largeicon.png
        smallicon.png    
    drawable-mdpi/  

        smallicon.png  
    drawable-hdpi/  

    drawable-xhdpi/  
        largeicon.png
        smallicon.png  
    drawable-xxhdpi/  
        smallicon.png  
    
answered by 25.05.2017 в 00:00
-1

Use:

.setIcon(R.drawable.smallicon)
    
answered by 25.05.2017 в 17:11