【发布时间】:2018-11-06 12:56:02
【问题描述】:
【问题讨论】:
-
您提到的问题中的答案对我不起作用。它给了我“与此操作关联的所有应用程序都已关闭、阻止或未安装”对话框
标签: android android-intent wallpaper
【问题讨论】:
标签: android android-intent wallpaper
试试下面的代码 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 获取
【讨论】:
Intent.FLAG_GRANT_READ_URI_PERMISSION。我会重新编辑我的答案。
你可以试试这个:
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);
【讨论】: