how to change profile picture on whatsapp - android

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

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.

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

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);

Related

Picking only images from gallery Android

I use
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, null), Photo.REQUEST_PICK_FROM_EXISTING);
Only images are getting displayed and with an option to use third party file manager apps which shows videos too. I want user to choose third party apps but choose only images. Is there any way to control it ?
Use the below code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
Hope this helps.

Sharing an image and text via whatsapp

I know this question has been asked many times and in many different ways (see here and here). However, I haven't been able to achieve it in the following way:
The picture and the title are in the same section. Then, there is the rest with the link in another section. I have achieved to put text and image together, but the picture is on the top of the text.
This is the code I am using:
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, shareContentByWhatsapp(contentType));
intent.putExtra(Intent.EXTRA_STREAM, getImage());
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Does anyone know how to obtain same result than in the picture?
As image you have shared,
In this case you just need to share the link,
image and link related content will be fetched by WhatsApp itself.
You can do like this:
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
mContext.startActivity(whatsappIntent);
or, you can share image with caption.
But, image you have shared, is whatsapp's functionality :-)

Opening image using Gallery does not show the Share option

In my app, I am opening my image using this code:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(picPathUriString)), "image/png");
startActivity(intent);
I run it on S2 and it opens the picture using the gallery as expected and showing all the capabilities of that gallery app (such as "Share" and "Send" ..etc)
On the S4, it shows the picture but the above options such as SHARE are not there. Although the Gallery on S4 has all the options if opened seperately
WHYYY? How can I make sure I get all the options?
Thanks
Try this....
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Uri uri = Uri.parse(Uri.parse(picPathUriString));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));

How to attach an image directly (automatically) to an email on Android?

I would like to ask if anyone knows how to attach an image directly to a send email portal instead of opening up the gallery for users to select?
Thanks a lot.
use the below code
File file = new File(Environment.getExternalStorageDirectory(),"image.png");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+file));
startActivity(Intent.createChooser(intent, "Share Picture Via Email"));

attach picture to email

Anyone knows how to attach images with
Intent intent = new Intent(Intent.ACTION_SENDTO);
I know how to do it with Intent.ACTION_SEND, but i would like to use SENDTO to remove the Bluetooth option for the user.
What i have works fine when not attaching the picture but when i use
intent.setData(pictureUri);
It tells me that there isn't any application to do the job.
Thank you for your help.
EDIT
Inserted the code that I have now. It "works fine" except that the image isn't getting attached.
Code
intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/html");
Uri uri = Uri.parse("mailto:?");
intent.setData(uri);
intent.putExtra(Intent.EXTRA_STREAM, picture);
intent.putExtra("subject", subject );
context.startActivity(Intent.createChooser(intent, "Share Via:"));
The picture is a Uri for a picture on the phone.
Anyone knows what can be the problem?
Try:
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
According to the API docs, SENDTO expects a recipient in the data field, not an attachment.
By saying intent.setData(pictureUri), you're basically trying to send a message to the picture. See here.
SEND accepts attachments via extras, so you could try the same for SENDTO.
For example:
intent.putExtra(Intent.EXTRA_STREAM, pictureUri);

Categories

Resources