Skip to content Skip to sidebar Skip to footer

In Android 8 (oreo) Intent Chooser Is Not Working To Set Wallpaper

I'm using following code snippet to set wallpaper. In all version lower than Android 8 (Oreo) it shows a picker to choose lock screen or home screen or both etc. But in Android 8 i

Solution 1:

try {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_ATTACH_DATA);
        File file = new File(path_of_file);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.setDataAndType(FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file), getMimeType(path_of_file);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, "Exception generated", Toast.LENGTH_SHORT).show();
    }
}


 private static String getMimeType(String url) {
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    }
    return type;
}

Solution 2:

   Intent setWith = new Intent(Intent.ACTION_ATTACH_DATA);
                    setWith.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    setWith.putExtra("SET_LOCKSCREEN_WALLPAPER", true);
                    setWith.addCategory(Intent.CATEGORY_DEFAULT);
                    setWith.setDataAndType(Uri.parse("file://" + imageFile.getAbsolutePath()), "image/*");
                    setWith.putExtra("mimeType", "image/*");
                   context.startActivity(Intent.createChooser(setWith, "Set As"));

Post a Comment for "In Android 8 (oreo) Intent Chooser Is Not Working To Set Wallpaper"