gpt4 book ai didi

android - getCropAndSetWallpaperIntent() 内容 Uri 错误

转载 作者:行者123 更新时间:2023-11-29 15:00:19 24 4
gpt4 key购买 nike

在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com