设置为墙纸意图对话框?

Set as Wallpaper intent dialog?

我正在尝试创建自己的墙纸应用程序,但我不知道如何启动此 Intent?

这是什么意图?如何将图像传递到设备默认墙纸应用程序?

尝试以下代码片段:

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 应该从 FileProvider in Android 7.0+ 如果你的 targetVersion 超过 7.0+

你可以试试这个:

private void startWallpaper(){
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
    startActivity(chooser);
}

ref 是 here

在您的清单文件中:

<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

如果你想传递自己的img,可以这样做:

WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);