Yug*_*agi 2 android android-contentresolver android-contentprovider android-wallpaper
getCropAndSetWallpaperIntent()在android中使用时出现此错误
D/Exception: java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*
Run Code Online (Sandbox Code Playgroud)
但是当我检查Content使用类型时,ContentResolver我得到了
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);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
小智 5
我遇到了同样的错误...
IllegalArgumentException:无法使用传递的 URI 来设置壁纸;检查 ContentProvider 返回的类型是否与 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
588 次 |
| 最近记录: |