设置为墙纸意图对话框?

时间:2018-11-06 12:56:02

标签: android android-intent wallpaper

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

enter image description here

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

2 个答案:

答案 0 :(得分:0)

尝试以下代码段:

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:"));

如果您的targetVersion大于7.0+,则PS:uri应该从Android 7.0+的FileProvider中获取

答案 1 :(得分: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);