[英]Is it possible to send push notification with message icon from the server side to android device via PyFCM
您可以将图片的网址附加到pyfcm中的消息数据有效负载上:
data_message = {
"icon_url" : "http//...."
}
push_service.notify_single_device(registration_id=registration_id,
message_body=message_body, data_message=data_message)
并在您的Android应用中获取“ icon_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;
}
}
然后使用setLargeIcon (Bitmap icon)
的NotificationCompat.Builder
到图像设置为通知图标
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.