我的应用程序显示一张图片,然后将其设置为墙纸设备。
我有代码,并且已经在某些设备上尝试过并成功运行。(联想 Vibe C Lolipop,Advan I7 Marshmallow)
但我在设备 Xiaomi Redmi 5 (Nougat) 上发现了一个问题
当我通过意图选择器将图片设置为壁纸时,没有“图库”选项
注意:我认为在小米上,Gallery Option 是设置图片作为设备壁纸的最佳选择。
我附上了Lenovo Vibe C(有图库选项)和小米红米5(没有图库选项)的截图
下面是我的代码片段
//I have picture in "Wallpaper Folder", its name is "IMG_Wallpaper.jpg"
File folderPict = new File(Environment.getExternalStorageDirectory() + File.separator + "Wallpaper Folder");
String pictName = "IMG_Wallpaper.jpg";
String destFileName = folderPict.getAbsolutePath() + "/" + pictName;
filePict = new File(destFileName);
// In this step, I already have filePict "IMG_Wallpaper.jpg" in folder "folderPict"
//get uri from external file
Uri uriPict = Uri.fromFile(filePict);
//set wallpaper by intent chooser
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uriPict, "image/*");
intent.putExtra("mimeType", "image/*");
startActivity(Intent.createChooser(intent, "Set as"));