How to change type to image/*

519 views Asked by At

I have an error

java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*
        at android.app.WallpaperManager.getCropAndSetWallpaperIntent(WallpaperManager.java:792)
        at lv.revo.inspicfootballhd.MainActivity.onTouch(MainActivity.java:244)

My code

Uri uri = ResourceToUri(getApplicationContext(), imageArray[j]);
File wallpaper_file = new File(uri.getPath());
Uri contentURI = getImageContentUri(getApplicationContext(), wallpaper_file.getAbsolutePath());

ContentResolver cr = this.getContentResolver();
Log.d("CONTENT TYPE: ", "IS: " + cr.getType(contentURI));

Intent intent = new Intent(wallpaperManager.getCropAndSetWallpaperIntent(contentURI));
startActivity(intent);

imageArray[] is basically an array, that contains drawables - R.drawable.v1, image format is jpg. cr.getType returns null. So, how do I change the type of contentURI to image/* as needed for method getCropAndSetWallpaperIntent?

UPDATE 1: I managed to get the method getCropAndSetWallpaperIntent working if I save the picture in my device before using the method and then getting the Uri of that picture. The picture's quality is not so good as the picture itself if I set the picture using default Set Wallpaper activity though, but that's a different problem.

0

There are 0 answers