我必须显示demo link
中的图片这是数据有效载荷数据
{"registration_ids":["","","","","","","","e132domchYE:APA91bEyVcuR8Qpl46
jNfs0CTg4gizFqUDze06wzdzaCsHOI0KwRqcV-Ml5ZlkWJF0b44pCJMWJT0Uk7ApvPoh8pOOtRO0xQWlnj9
Sa8Aii15tSR_U8KB4Dr"],"data":{"title":"50%+discount+sale","message":"grab+now",
"image":"http:\/\/demo.ivdisplays.net\/broadcast\/school_admin\/notification
_images\/thumbnail\/thumb_1490003439class routing.png"}}
我必须在推送通知中的以下链接中显示图像,就像电子商务应用程序一样。
答案 0 :(得分:0)
试试这个,会起作用
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
Bitmap bitmap = getBitmapFromURL(url);
NotificationCompat.BigPictureStyle s = new NotificationCompat.BigPictureStyle().bigPicture(bitmap);
s.setSummaryText("Image");
nBuilder.setStyle(s);
nBuilder.setSmallIcon(R.mipmap.ic_launcher);
创建方法getBitmapFromURL
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;
}
}
mNotificationManager.notify(0, nBuilder.build());