Search code examples
androidandroid-contentproviderandroid-contentresolverandroid-wallpaper

getCropAndSetWallpaperIntent() Content Uri Error


I am getting this error when using getCropAndSetWallpaperIntent() in android

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

But when I check for the type of Content using ContentResolver I am getting

D/CONTENT TYPE:: IS: image/jpeg

then why is Wallpaper Manager is giving me content error ?

Here is the code I am using to get Image 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);
}

Any ideas ?


Solution

  • I'm getting the same error...

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

    I've checked the uri type (getActivity().getContentResolver().getType(uri);)... says the type is image/jpeg so kinda stumped!!

    This is what I've done... will at least give it a chance on Oreo

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