我正在尝试使用ImageLoader显示带有外部图像链接的通知,但没有任何运气。 Logcat没有显示任何错误,通知根本没有显示。
这是我的代码:
void shownot()
{
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(getSingleItemLargeIcon(IMAGE_LINK_URL))
.setTicker("test test test test test test")
.setContentTitle("test test test test test test")
.setAutoCancel(true)
.setContentText("test test test test test test");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
private Bitmap getSingleItemLargeIcon(String imageUri) {
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
imageLoader.loadImage(imageUri, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
bitmap = arg2;
}
@Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
});
return bitmap;
}
我错过了什么吗?
答案 0 :(得分:1)
终于明白了。您似乎需要在显示通知的通知中设置 setSmallIcon():
void shownot() {
NotificationManager mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, PhotoIntentActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.microphone);// download this bitmap from internet
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setLargeIcon(bitmap).setSmallIcon(R.drawable.icon)
// this is also required
.setTicker("+1 notification").setContentTitle("Awsome Title")
.setAutoCancel(true).setContentText("Awsome Text");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
答案 1 :(得分:0)
由于Android中的通知为RemoteViews
,因此您无法直接更新内容。
相反,您有2个选择:
1)在致电mNotificationManager.notify()
之前下载图片;正如非法论据对您的问题的评论所述。
2)保存 ID 号码,并在下载图片时再次使用新通知调用mNotificationManager.notify(id, notification)
。这将使其看起来好像有一个“新”通知(滚动条文本将再次滚动,等等)。