gpt4 book ai didi

php - 如何在 android 推送通知中显示来自链接的图像?

转载 作者:行者123 更新时间:2023-11-28 21:11:34 25 4
gpt4 key购买 nike

我必须显示来自 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"}}

我必须像电子商务应用一样在推送通知中显示以下链接中的图片。

最佳答案

试试这个,会成功

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);

Create Method 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());

关于php - 如何在 android 推送通知中显示来自链接的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42900826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com