How to set a large icon for GCM notification

In the GCM 3.0 notification, when the application is in the background, the GCM SDK itself will process it. But I can’t install the Big Icon, a notification generated when the application is in the background.

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

myicon here appears as a small icon.

Can I set a large icon for notification when the application is in the background?

+7
android google-cloud-messaging
source share
2 answers

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 . There you must override onReceive so that you can create and display a notification as you like.

The official notification docs explain all the options, including setting a large icon here

There is also sample code here .

0
source share

You can set a large icon for your notification using the setLargeIcon() method during notification creation.

 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()); 
0
source share

All Articles