2

This is for a general notification app. I've managed to capture and set the large icon for the notification since it accepts a Bitmap type as a parameter, but setting the small icon is proving to be a lot more tricky. It only accepts an int resource ID. Since I have no idea what application might be sending a notification to my listener, I would have to generate it dynamically. I can get the small icon by listening for incoming notifications and extracting it, but I can't seem to find a way to set it via its resource ID.

I don't think it's possible, but just want to confirm. If so, is there a workaround, or would I have to manually load small icons of specific apps I want to support into my Drawable folder and then use the resource Id from there? That sounds like a hassle seeing that I've already gotten the right icon, but can't load it in! Below is my code:

public class NotificationService extends NotificationListenerService {

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
                          Bundle extras = sbn.getNotification().extras;
                          int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);; 

                    //Building Notifications
                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext(id1))
                            .setSmallIcon(R.mipmap.ic_launcher) //This gives an error
                            .setContentTitle("My Title")
                            .setContentText("My Text");

                    NotificationManager notificationManager =
                            (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

                    notificationManager.notify(notiId, mBuilder.build());

}
}
Kyle
  • 598
  • 1
  • 7
  • 25

2 Answers2

0

Small icon might not load if it exceeds the size prescribed by Android.Generally we can load small icons through images stored in resource folder only.

can get the details regarding icon sizes for push notifications from the following link GCM Push Notification Large Icon size

Community
  • 1
  • 1
Ruthvik
  • 11
  • 1
0

Small Icons in push notifications cannot be added dynamically. Large Icons can be added dynamically by running an Async task. Application will crash if there is no small icon. Small Icon is mandatory for PushNotification.

Ruthvik
  • 11
  • 1