How to change type to image/*

孤者浪人 提交于 2019-12-12 03:37:23

问题


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.

来源:https://stackoverflow.com/questions/30793404/how-to-change-type-to-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!