GCM推送通知图标

4
在GCM的官方文档(链接在此)中,他们提到了如何通过以下示例为推送通知添加图标。
{
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    }
  }

我的问题是,“myicon”是图标的名称,它在哪里存在? 例如:我在Android Studio的项目中有一个名为“myicon.png”的drawable文件夹中,那么它在哪里呢? 请有人解释一下,先感谢了。


是的,你会在你的drawable中拥有它。所以根据它的名称,你将制定你的逻辑或使用名称来获取图标。 - Arjun Gurung
@ArjunGurung,我不明白你的意思,你是说我还需要在Android端编写一些代码吗? - Mohammad Haidar
你好,你有@Haidar。 - Arjun Gurung
1个回答

0

使用来自drawable文件夹的应用程序图标,例如.setSmallIcon(R.drawable.appicon),其中appicon是.png文件。

或者使用以下代码:

  NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
         .setSmallIcon(R.drawable.icond)
         .setContentTitle("Start Launcher")
         .setContentText(message)
         .setAutoCancel(true)
         .setOngoing(true)
         .setWhen(System.currentTimeMillis())
         .setContentIntent(pendingIntent);

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

   notificationManager.notify(ID_NOTIFICATION , notificationBuilder.build());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接