0

I want to access the dp (profile picture) option of whatsapp using android code I have used that code

Code

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM,uri);
            intent.setPackage("com.whatsapp");
            intent.setType("image/*");
            startActivity(intent);

but every time it open with share image option instead of change dp picture option in whatsapp i don't know where i am doing mistake I hope anyone here can help me. Thanks

guys i corrected question what actually i am asking

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
vicky
  • 41
  • 1
  • 3

3 Answers3

2

Finally after 1 day of exploring I came up with the Solution

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri), "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, "Set image as"), 200);

With the help of this code snippet, you can set profile photo of Whatsapp as well as Contacts.

Pankaj Lilan
  • 4,245
  • 1
  • 29
  • 48
  • 1
    this code only work less than api 22, in 23 needs file provider can you compatible by adding fileprovider in this code ..i need that – Najaf Ali Apr 03 '19 at 12:55
  • @NajafAli To implement the file provider. Please refer my [this](https://stackoverflow.com/a/45751453/4629101) answer. – Pankaj Lilan Nov 26 '19 at 02:42
0

You can open Whatsapp or share image and video but can't change profile picture from your own app.

zapping
  • 4,118
  • 6
  • 38
  • 56
iasoftsolutions
  • 251
  • 2
  • 4
0
   if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N)
    {
        uri=FileProvider.getUriForFile(getApplicationContext(),BuildConfig.APPLICATION_ID+".provider",new File(list.get(position)));
    }else{
        uri=Uri.parse(list.get(position));
    }
    Intent intent=new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setDataAndType(uri,"image/*");
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra(Intent.EXTRA_STREAM,uri);
    startActivity(intent);
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 17 '21 at 12:49