0

My application shows a picture and then set it as wallpaper device.

I have code and already try it on some devices and running successfully. (Lenovo Vibe C Lolipop, Advan I7 Marshmallow)

But I found a problem on device Xiaomi Redmmi 5 (Nougat)

When I set picture as wallpaper by intent chooser, there was no "Gallery" option

Note: I think on Xiaomi, Gallery Option is best choice to set picture as a device wallpaper than others

I attached screenshoot of Lenovo Vibe C (have Gallery option) and Xiaomi Redmi 5 (No gallery option)

Screenshoot on Lenovo and Xiaomi

Below is my code snippet

//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"));
danangmr
  • 21
  • 3

1 Answers1

0
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent , RESULT_GALLERY );

and for receiving result

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (null != data) {
        imageUri = data.getData();
        //Do whatever that you desire here. or leave this blank
    }
}
Ghulam Moinul Quadir
  • 1,638
  • 1
  • 12
  • 17
  • Hi Ghulam, thx for your respond. Your solution use Intent.ACTION_PICK but I'am so sorry because I need solution for Intent.ACTION_ATTACH_DATA. My code already picked the "IMG_Wallpaper.jpg" from storage but there was no choice/option to set it as wallpaper by Gallery – danangmr May 13 '18 at 03:55