0
我想顯示通知與存儲在我的SD卡用戶的圖像,我得到的是圖像的URL,然後我怎麼可以在通知其設置爲largeIcon如何設置本地圖像在Android通知
我的方法是爲
String userAvatarURL = /storage/emulated/0//Planetskool/Media/Profile Images/ferrari_f12_need_for_speed_rivals-HD%20(1)P47cs5ng7hg4Ft5wquality_50.jpg
private void displayNotificationMessage(String message)
{
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
Log.d("UserAvatarURL", "UserAvatarURL = " + userAvatarURL);
mBuilder.setLargeIcon(grabImageFromUrl(userAvatarURL));
mBuilder.setContentTitle(userName);
mBuilder.setContentText(message);
Intent resultIntent = new Intent(this, MessageThreadActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MessageThreadActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
}
private Drawable grabImageFromUrl(String url) throws Exception {
return Drawable.createFromStream((InputStream)new URL(url).getContent(), "src");
}
使用此:'NotificationCompat.Builder mBuilder =新notificationCompat.Builder(本) .setLargeIcon(位圖)' – 2015-02-11 12:48:36