【问题标题】:Set as Wallpaper intent dialog?设置为墙纸意图对话框?
【发布时间】:2018-11-06 12:56:02
【问题描述】:

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

这是什么意图?如何将图像传递给设备默认壁纸应用?

【问题讨论】:

标签: android android-intent wallpaper


【解决方案1】:

试试下面的代码 sn-p:

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 获取

【讨论】:

  • 这给了我以下错误:“与此操作关联的所有应用程序都已关闭、阻止或未安装。”
  • 您的设备是哪个 Anroid 版本?
  • 我在我的华为荣耀 V8 中做了一些事情,它工作正常。顺便说一下,你应该在 Android 7.0+ 的 Intent 中添加Intent.FLAG_GRANT_READ_URI_PERMISSION。我会重新编辑我的答案。
  • 明天会检查并更新您。但它在 api 21 和 26 上进行了测试
【解决方案2】:

你可以试试这个:

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

参考是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);

【讨论】:

  • 如何用第一种方法传递图像?第二种方法无效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多