gpt4 book ai didi

android - 使用 ImageLoader 显示带有外部图像链接的通知

转载 作者:行者123 更新时间:2023-11-30 02:40:23 25 4
gpt4 key购买 nike

我正在尝试使用 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;
}

我错过了什么吗?

最佳答案

终于明白了。似乎您需要在通知中设置 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());
}

关于android - 使用 ImageLoader 显示带有外部图像链接的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25840683/

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