How To GetCropAndSetWallpaperIntent(Uri ImageUri) To Work?
So, there are two questions that are the same as this( How to use getCropAndSetWallpaperIntent method in WallpaperManager? AND How to use getCropAndSetWallpaperIntent? ), but there
Solution 1:
Like the error says, you need a content URI. Content URIs allow you to share files with temporary read and write permissions.
Check out: Get a Content URI from a File URI?
Solution 2:
File wallpaper_file = new File(uri.getPath());
Uri contentURI = getImageContentUri(getApplicationContext(),wallpaper_file);
ContentResolver cr = this.getContentResolver();
Log.d("CONTENT TYPE: ", "IS: " + cr.getType(contentURI));
Intent intent = new Intent(wallpaperManager.getCropAndSetWallpaperIntent(contentURI));
startActivity(intent);
public static Uri getImageContentUri(Context context, File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID},
MediaStore.Images.Media.DATA + "=? ",
new String[]{filePath}, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.MediaColumns._ID));
Uri baseUri = Uri.parse("content://media/external/images/media");
return Uri.withAppendedPath(baseUri, "" + id);
} else {
if (imageFile.exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}
}
Post a Comment for "How To GetCropAndSetWallpaperIntent(Uri ImageUri) To Work?"