为GCM推送通知添加一个图标,而不是默认通知

时间:2016-08-31 13:28:28

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

我知道设置标题,消息和声音很热, 但是我必须在从服务器发送推送通知时替换默认图标。 我怎么能这样做?

提前致谢。

2 个答案:

答案 0 :(得分:1)

尝试这个

NotificationManager notificationManager = (NotificationManager)
            getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this);
// call your local image location 
mBuilder.setSmallIcon(R.mipmap.app_icon);


// if you want to set image from url then use it 
mBuilder.setSmallIcon(R.mipmap.app_icon).setLargeIcon(getBitmapFromURL("image url"));

public Bitmap getBitmapFromURL(String strURL) {
    try {
        URL url = new URL(strURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

答案 1 :(得分:0)

写成here

  

图标   字符串

     

通知图标。

     

Android:将可绘制资源的通知图标设置为myicon   myicon。如果您未在请求中发送此密钥,则FCM将显示   在应用清单中指定的启动器图标。

     

网络:用于通知图标的URL。

     

平台:Android,Web

因此,只需在 icon 字段中提供要使用的另一个图标图像文件的URL。