android - getCropAndSetWallpaperIntent() 内容 Uri 错误

标签 android android-contentprovider android-contentresolver android-wallpaper

在 android 中使用 getCropAndSetWallpaperIntent() 时出现此错误

D/Exception: java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*

但是当我使用 ContentResolver 检查 Content 的类型时,我得到了

D/CONTENT TYPE::IS: image/jpeg

那为什么 Wallpaper Manager 给我内容错误?

这是我用来获取图片 URI 的代码

    public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    tempPath = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    Log.d("URI OF SET IMAGE", tempPath);
    ContentResolver cr = this.getContentResolver();
    Log.d("CONTENT TYPE: ", "IS: " + cr.getType(Uri.parse(tempPath)));
    return Uri.parse(tempPath);
}

有什么想法吗?

最佳答案

我遇到了同样的错误...

IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*

我已经检查了 uri 类型 (getActivity().getContentResolver().getType(uri);)... 说类型是 image/jpeg 所以有点难过!!

这就是我所做的......至少会在奥利奥上给它一个机会

try {
    Intent intent = WallpaperManager.getInstance(getActivity()).getCropAndSetWallpaperIntent(contentUri);
    //startActivityForResult to stop the progress bar
    startActivityForResult(intent, ACTIVITY_CROP);
} catch (IllegalArgumentException e) {
    // Seems to be an Oreo bug - fall back to using the bitmap instead
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), contentUri);
    WallpaperManager.getInstance(getActivity()).setBitmap(bitmap);
    imageLoadProgress.setVisibility(View.GONE);
}

关于android - getCropAndSetWallpaperIntent() 内容 Uri 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47254498/

相关文章:

java - 使用 ContentResolver 更新联系人组时更新不起作用

android - com.android.volley.ServerError 错误 instanceof VolleyError

Android 获取所有联系人列表(姓名、电子邮件、电话)需要超过一分钟的时间来获取大约 700 个联系人

android - 如何仅从元素的一侧删除边框?

自定义帐户类型的 Android 1.x Contacts.Extensions?

android - 在多个 Android 应用程序之间共享和持久化数据

java - 如何在 Android 上查询 ContentProvider 的值不为 null?

android - 内容观察者是观察者模式的实现吗?

java - 从相册中选取照片后 Android 应用程序消失

android - AppCompat v7 : Should I use Framework FragmentManager or SupportFragmentManager?