I am trying to create my own wallpaper app and I can't figure out how to start this intent?
What is this intent? How do I pass image to device default wallpaper app?
I am trying to create my own wallpaper app and I can't figure out how to start this intent?
What is this intent? How do I pass image to device default wallpaper app?
Try following code snippet:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//add this if your targetVersion is more than Android 7.0+
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
PS:uri should get from FileProvider in Android 7.0+ if your targetVersion is more than7.0+
You could try this:
private void startWallpaper(){
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
startActivity(chooser);
}
ref is here
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
If you want to pass own img, could do like below:
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);