Reputation: 21
I am using the following code to set the wallpaper from an image in a drawable:
Intent setAsIntent = new Intent();
setAsIntent.setDataAndType(uri, "image/*");
setAsIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setAsIntent.setAction("android.intent.action.ATTACH_DATA");
Intent chooserIntent = Intent.createChooser(
setAsIntent, "set as");
But when startActivity, it only shows a message:
No apps can perform this action
Upvotes: 2
Views: 1205
Reputation: 773
I did discover a workaround:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
or try to use
WallpaperManager
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
If you have image bitmap then use this
wallpaperManager.setBitmap(useThisBitmap);
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
Upvotes: 2