Android 如何为GCM通知设置大图标
在Android 如何为GCM通知设置大图标,android,google-cloud-messaging,Android,Google Cloud Messaging,在GCM 3.0中,当应用程序处于后台时,通知将由GCM SDK自身处理。但我无法设置应用程序处于后台时创建的通知的大图标 { "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark", "icon" : "myicon"
GCM 3.0
中,当应用程序处于后台时,通知将由GCM SDK
自身处理。但我无法设置应用程序处于后台时创建的通知的大图标
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}
此处发送的myicon
显示为小图标
当应用程序处于后台时,是否可以为通知设置大图标?我建议更新为使用
FCM
和Firebase进行通知,但如果您现在正在使用GCM
,我假设您有一个扩展BroadcastReceiver
的注册接收器类。在那里,您应该覆盖onReceive,这样您就可以随心所欲地构造和显示通知
通知上的官方文档解释了所有选项,包括设置大图标
还有一些示例代码。在生成通知时,可以使用
setLargeIcon()
方法为通知设置大图标
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());