How to use getCropAndSetWallpaperIntent?
Asked Answered
J

1

3

I tried to use getCropAndSetWallpaperIntent method but I got an error.

Here is my code :

Uri uri = Uri.parse("content://" + getFilesDir() + "/"+ image.path);
ContentResolver contentResolver = getContentResolver();
contentResolver.getType(uri); // Type is null
Intent intent = wallpaperManager.getCropAndSetWallpaperIntent(uri);
intent.setType("image/*");
startActivityForResult(intent, 42);

Here is what I got in my logs :

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

Can you help me please?

Joppa answered 13/1, 2014 at 14:44 Comment(1)
did you get a solution?Meant
H
-1

You have to query the MediaStore without using the "content://" protocol, for instance like this (code can be improved):

String[] paths = {"/example.png"};
final String[] FIELDS = { MediaStore.MediaColumns._ID };
// Images
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor ca = context.getContentResolver().query(uri, FIELDS, MediaStore.MediaColumns.DATA + "=?", paths, null);
for (ca.moveToFirst(); !ca.isAfterLast(); ca.moveToNext()) {
   int id = ca.getInt(ca.getColumnIndex(MediaStore.MediaColumns._ID));
   uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
   found = true; 
}
ca.close();

if (found) {
   return uri;
}
Hydrotherapeutics answered 25/7, 2015 at 15:1 Comment(1)
Still the same error. It is returning content://media/external/images/media/63, where the path of file is "/storage/emulated/0/Pictures/catamaran-199153_1920.jpg". This value when passed to getCropAndSetWallpaperIntent() throws exception : java.lang.IllegalArgumentException: Cannot use passed URI to set wallpaper; check that the type returned by ContentProvider matches image/*Meant

© 2022 - 2024 — McMap. All rights reserved.