Android GetCropandSetWallperIntent()内容Uri错误

Android GetCropandSetWallperIntent()内容Uri错误,android,android-contentprovider,android-contentresolver,android-wallpaper,Android,Android Contentprovider,Android Contentresolver,Android Wallpaper,我在android中使用getcropandsetwallperintent()时遇到此错误 D/Exception: java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/* 但是当我使用ContentResolver检查内容的类型时,我得到了 D/内容类型::IS:ima

我在android中使用
getcropandsetwallperintent()
时遇到此错误

D/Exception: java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*
但是当我使用
ContentResolver
检查
内容的类型时,我得到了

D/内容类型::IS:image/jpeg

那么为什么
壁纸管理器
给我的内容有错误

下面是我用来获取图像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:无法使用传递的URI设置墙纸; 检查ContentProvider返回的类型是否与映像匹配/*

我已经检查了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);
}

是的,我也认为它与Oreo有关,因为它在以前的设备上工作,谢谢你的回答,但还有一点信息:我在GetCropandsetWallperIntent()中仔细阅读了代码,我认为实际的错误是某些设备/操作系统版本没有裁剪和设置活动。正在抛出的异常只是具有错误的文本。事实上,看看API28的代码,它似乎从来没有检查过该函数中的MIME类型。我猜是pre-oreo,它确实检查了MIME类型和抛出。但在重构后,异常文本从未更新。@Adam我的目标是API 29,而GetCropandsetWallperIntent()在某些具有相同糟糕消息的设备上失败。代码仍然没有检查任何MIME类型,但仍然给出此错误。此外,我还尝试输入MIME类型,其目的是使用给定的方法从uri中提取“image/jpeg”,令我惊讶的是,GetCropandsetWallperIntent()在已经工作的设备上停止工作。所以现在我已经使用了上面的解决方案。安卓是。。。。