android - Glide : load image to push notifications

标签 android notifications push android-glide remoteview

我正在尝试使用 Glide 将图像加载到推送通知,但它是这样说的:

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/

问题是在推送通知中应用程序没有运行,所以没有主线程。有什么建议吗?

最佳答案

这样试试:

    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);
        }
    });

关于android - Glide : load image to push notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41861094/

相关文章:

cross-browser - 是否有用于跨浏览器桌面通知的 JavaScript 库?

Android通知栏按钮变得没有响应

javascript - 合并具有相同 id 的数组

android - 从 Android 应用程序控制 DOM 元素

Android 风格 - 在 R 文件中找不到符号变量

android - 尝试从本地主机获取 xml 时在 Android 应用程序中获取 404

java - 如何明确告诉 Proguard 删除完整的包?

Android 无障碍服务检测通知

git - 在 git 中是否可以一个一个地推送提交而不是一次推送所有提交?

mercurial - 无法 merge 到 Mercurial 中