滑行:加载图像以推送通知 [英] Glide: load image to push notifications
本文介绍了滑行:加载图像以推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Glide将图像加载到推送通知中,但是它说的是:
I am trying to load an image to a push notification using Glide but it says this:
FATAL EXCEPTION: Thread-9730
Process: com.monkingme.monkingmeapp, PID: 24226
java.lang.IllegalArgumentException: You must call this method on the main thread at com.bumptech.glide.util.Util.assertMainThread(Util.java:135)
以及使用的代码:
NotificationTarget notificationTarget = new NotificationTarget(
context,
rv,
R.id.remoteview_notification_icon,
notification,
NOTIFICATION_ID);
Glide.with(context.getApplicationContext())
.load(item.getString("cover_img"))
.asBitmap()
.placeholder(placeholder)
.error(placeholder)
.into(notificationTarget);
我正在使用Aerogear的MessageHandler-> https://aerogear.org/docs/guides/aerogear-android/push/
I am using MessageHandler from Aerogear --> https://aerogear.org/docs/guides/aerogear-android/push/
问题在于,在推送通知中应用程序未运行,因此没有主线程.有什么建议吗?
The thing is that in a push notification the app is not running, so there isn't a main thread. Any suggestion?
推荐答案
尝试这种方式:
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Glide.with(context.getApplicationContext())
.load(item.getString("cover_img"))
.asBitmap()
.placeholder(placeholder)
.error(placeholder)
.into(notificationTarget);
}
});
这篇关于滑行:加载图像以推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文