答案 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);