0

welcome everyone

I'm trying writing a program to set the wallpaper, lock screen and contact picture etc from imageView by action attach data or any other way of doing the same.

Please see the pictures

image 1

image2


some code :

   Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
   setAs.setDataAndType(uri,"image/jpg");
   setAs.putExtra("mimeType", "image/jpg");
   startActivity(Intent.createChooser(setAs, "Set Image As"));

When the application runs out show me the message : no app can perform this action

I add permission in manifest file :

  <uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

Thank you very much for your time

1 Answers1

0

I found solution , The cause of the problem is ( URI ) it should be this way :

    Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
     // i : integer variable (index of array contains my images ) 
    setAs.setDataAndType(Uri.parse(new File("/storage/emulated/0/pictures/wall/wall.jpg").toString()), "image/*");
    setAs.putExtra("mimeType", "image/*");
    setAs.addCategory(Intent.CATEGORY_DEFAULT);
    setAs.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(setAs, "Set Image As"));

The above code does not set the image to the contacts .. I am continuing to try and if I find the solution I will put it here