【问题标题】:GCM push notification iconGCM 推送通知图标
【发布时间】:2016-09-01 07:14:18
【问题描述】:

在 GCM here 的官方文档中,他们提到了如何通过此示例为推送通知放置图标

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

我的问题是“myicon”是图标的名称,它存在于哪里? 例如:我在 android studio 的项目中有可绘制的“myicon.png”? 或者它在哪里? 请有人解释并提前感谢

【问题讨论】:

  • 是的,你会在你的drawable中拥有它。因此,根据其名称,您将制定逻辑或使用名称来获取图标。
  • @ArjunGurung 我不明白你的意思是我必须在 Android 端写一些代码吗?
  • 是的,你有@Haidar

标签: android push-notification google-cloud-messaging


【解决方案1】:

使用drawable 中的应用图标,例如.setSmallIcon(R.drawable.appicon),其中appicon 是drawable 文件夹中的.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());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-21
    • 2015-03-08
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多