无法使用Glide将本地磁盘映像加载到主窗口小部件远程视图中

时间:2018-10-03 12:30:38

标签: android android-glide

我尝试使用Glide将本地磁盘jpg图像加载到Home Widget中。

但是,我遇到以下错误,我不知道如何调试它。

Uncaught remote exception!  (Exceptions are not yet supported across processes.)
    java.lang.RuntimeException: Failed to unparcel Bitmap
        at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1793)
        at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1784)
        at android.widget.RemoteViews$BitmapCache.<init>(RemoteViews.java:1176)
        at android.widget.RemoteViews.<init>(RemoteViews.java:2433)
        at android.widget.RemoteViews.<init>(RemoteViews.java:2419)
        at android.widget.RemoteViews$3.createFromParcel(RemoteViews.java:3865)
        at android.widget.RemoteViews$3.createFromParcel(RemoteViews.java:3864)
        at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:179)
        at android.os.Binder.execTransact(Binder.java:697)

这是我用来将本地磁盘映像加载到RemoteViews

中的代码
 // I had confirmed the path is accessible without permission required.
 // context is application context.
 RemoteViews rv = new RemoteViews(PACKAGE_NAME, R.layout.collage_view_row);
 AppWidgetTarget awt = new AppWidgetTarget(context, R.id.image_view_0, rv, appWidgetId);
 Glide.with(context)
    .asBitmap()
    .load("/storage/emulated/0/Android/data/com.yocto.wenote/files/attachment/c52ba5f3-04fd-4ee8-a662-c058d83c96ff.jpg")
    .into(awt);

我的布局文件collage_view_row.xml非常简单。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <ImageView
        android:layout_margin="1dp"

        android:visibility="visible"
        android:id="@+id/image_view_0"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true" />

    <ImageView
        android:layout_margin="1dp"

        android:visibility="visible"
        android:id="@+id/image_view_1"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true" />

    <ImageView
        android:layout_margin="1dp"

        android:id="@+id/image_view_2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop" />
</LinearLayout>

有什么办法可以调试出问题了吗?

1 个答案:

答案 0 :(得分:0)

我认为您应该在位置之前加上“ file://”。

这可能会有所帮助:

Link