Skip to content Skip to sidebar Skip to footer

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:

Filewallpaper_file=newFile(uri.getPath());
 UricontentURI= getImageContentUri(getApplicationContext(),wallpaper_file);

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

 Intentintent=newIntent(wallpaperManager.getCropAndSetWallpaperIntent(contentURI));
startActivity(intent);

publicstatic Uri getImageContentUri(Context context, File imageFile) {
    StringfilePath= imageFile.getAbsolutePath();
    Cursorcursor= context.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            newString[]{MediaStore.Images.Media._ID},
            MediaStore.Images.Media.DATA + "=? ",
            newString[]{filePath}, null);

    if (cursor != null && cursor.moveToFirst()) {
        intid= cursor.getInt(cursor
                .getColumnIndex(MediaStore.MediaColumns._ID));
        UribaseUri= Uri.parse("content://media/external/images/media");
        return Uri.withAppendedPath(baseUri, "" + id);
    } else {
        if (imageFile.exists()) {
            ContentValuesvalues=newContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);
            return context.getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            returnnull;
        }
    }
}

Post a Comment for "How To Getcropandsetwallpaperintent(uri Imageuri) To Work?"