我最近开始使用Urban Airship为我的公司。我必须为推送通知创建自定义布局。我的问题是我需要获取图像的url才能使用Picasso在远程视图中设置图标。每个人都使用资源文件夹中存在的drawable来设置通知图标。此外,我没有找到任何可以给我图像网址的getter方法。
此外,我无法找到解决同一问题的任何好例子。
答案 0 :(得分:0)
您需要将该网址作为额外内容发送。使用push API:
的示例"notification": {
"alert": "Notification alert",
"android": {
"extra": {
"url": "some url"
}
}
}
如果你正在使用作曲家,你可以在android覆盖下设置额外内容。
然后在设备上,您可以使用以下方式访问额外内容:
String url = message.getExtra("url", null);
或者,如果您使用的是较旧的SDK版本:
String url = message.getPushBundle().getString("url");
答案 1 :(得分:0)
将此方法粘贴到您的班级中:
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;
}
}
调用此方法从url获取位图:
Bitmap bitmap = getBitmapFromURL("https://graph.facebook.com/YOUR_USER_ID/picture?type=large"); // Change the url with your own url.
在您的通知对象中设置此图像如下:
builder.setLargeIcon(bitmap);
对于Urban Airship,还有一种发送和接收多个值的方法,您可以通过Payload发送值(String,Sound Name,Json等)。我建议你把你的网址作为一个关键值对在Json中发送,并通过Json在你的应用程序中获取它。检查此链接:
https://docs.urbanairship.com/reference/libraries/python/1.0.0/push.html#notification-payload