7

In GCM 3.0 notification when the app is in background will be handled by GCM SDK itself. But I am Unable to set the Large icon the the notification created when the app is in background.

{
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark",
        "icon" : "myicon"
    }
}

The myicon sent here is displayed as the small icon.

Is it possible to set large icon for notification when the app is in background?

Let'sRefactor
  • 3,303
  • 4
  • 27
  • 43
null pointer
  • 5,874
  • 4
  • 36
  • 66

2 Answers2

0

I would recommend updating to use FCM and Firebase for notifications but if you are using GCM right now I assume you have a registered receiver class that extends BroadcastReceiver. In there you should override onReceive so you can construct and display the notification however you like.

The official docs on notifications explain all the options including setting the large icon here

There's also some sample code here.

Abtin Gramian
  • 1,630
  • 14
  • 13
0

You can set large icon for your Notification using setLargeIcon() method while you are building notification.

public class MyGcmListenerService extends GcmListenerService {

private static final String TAG = "MyGcmListenerService";
............................
.............................

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setColor(ContextCompat.getColor(this, R.color.colorAccent))
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.icon))
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setGroupSummary(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(job_title))

            .setContentIntent(pendingIntent);

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

    notificationManager.notify((int) System.currentTimeMillis() /* ID of notification */, notificationBuilder.build());
Rajesh.k
  • 2,327
  • 1
  • 16
  • 19