getCropAndSetWallpaperIntent() 内容 Uri 错误

getCropAndSetWallpaperIntent() Content Uri Error

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

有什么想法吗?

有同样的问题。好像跟奥利奥有关。 在旧版本 Android 上工作正常。

现在我已经这样做了

try {
  val intent = manager.getCropAndSetWallpaperIntent((Uri.parse(path)))
}
catch (e: Throwable) {
  AlertDialog.Builder(this)
    .setTitle("Oops")
    .setMessage("${e.localizedMessage}\n\nThe photo has been saved to your Pictures folder. Try setting it as wallpaper manually.")
    .setPositiveButton("OK", null)
    .show()
}

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

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