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,352
  • 21
  • 80
  • 110
vicky
  • 41
  • 1
  • 3

2 Answers2

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
  • 3,896
  • 1
  • 29
  • 47
  • 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,043
  • 6
  • 40
  • 54
iasoftsolutions
  • 231
  • 2
  • 4