Android WhatsApp image sharing - android

I am developing an application in which i have to share image and text on WhatsApp with in my application.
Is there any best way to do that.
I am capturing my application screen, and need to send that image via WhatsApp

After Spending some time I am able to share Image and Text to whatsapp from my application using this code :
String smsNumber = "91xxxxxxxxxx"; //without '+'
try {
Uri imageUri = null;
try {
imageUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(),
BitmapFactory.decodeResource(getResources(), R.drawable.whatsapp_image), null, null));
} catch (NullPointerException e) {
}
Intent shareIntent = new Intent("android.intent.action.MAIN");
shareIntent.setType("*/*");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "App - Link");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra("jid", smsNumber + "#s.whatsapp.net"); //phone number without "+" prefix
shareIntent.setPackage("com.whatsapp");
startActivity(Intent.createChooser(shareIntent, "send"));
} catch (Exception e) {
}
Happy Coding :)

Related

How to send Image from Firebase Database ?

I have created Database in firebase and from there I am getting an Url of Image. So I want to share that image but below code did not work for me... Please Help me.
String pictureFile = mdata.get(holder.getHolderPosition).getImage();
Uri imageUri = Uri.parse(pictureFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Send to Whattssap
shareIntent.setPackage("com.whatsapp");
//Even you can add text to the image
shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
You can upload your image in Firebase Storage. here's the link Documentation

How to send picture with whatsapp android

Hi everyone I'm an android develeloper and in my app I need to share an image with a text by whatsapp, the problem is that Uri method doesn't work anymore. This is Uri method:
Uri imageUri = Uri.parse(pictureFile.getAbsolutePath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
So is there any method different from this one?

how to share image from sever to whatsapp

hey guys i want to share image from server to whatsapp but its give an error image share failed can you tell me can i share image directly server to whatsapp what i am doing something wrong
this is my code
Intent shareIntent = new Intent();
Uri imageUri = Uri.parse("http://stacktoheap.com/images/stackoverflow.png"); // here is my selected url
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, img_txt);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
help me friends
my answer is simple first download image from sever and then share image on whatsapp
try this code
String imagePath =Environment.getExternalStorageDirectory() + "your folderpath"+"imagename";
File f=new File(imagePath);
Uri uri = Uri.fromFile(f);
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_TEXT,"your text"); //want share text with image
share.putExtra(Intent.EXTRA_STREAM, uri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(share);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
You are getting issue because you are sharing image and text both
Infact whatsapp doesn't allow to share image and text simultaneously, try either image only

Can we share image/text to whatsapp to specific contact number in android

In my application i need to share image/text to whatsapp. Sharing images or text is working fine. But my requirement is sharing images/text to specific recipant. For that i have mobile number. So before sharing, first of all that number is having whatsapp or not?. Then if the number having whatsapp, then bydefault select that specific number. If the number is not having whatsapp then simply redirect to whatspp. then they select the recipant and share to that recipant.
For sharing i am using the following code. This code is working fine for sharing.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (images.size() > 0) {
Log.e("count==", "val## " + images.size());
shareIntent
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, images);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.setType("text/plain");
}
shareIntent.setPackage("com.whatsapp");
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ManageOnlineBuyLeadActivity.this,
"Whatsapp have not been installed.", Toast.LENGTH_SHORT)
.show();
}
And for sharing particular recipant i have changed the follwing lines
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
to
Uri mUri = Uri.parse("smsto:+number");
Intent shareIntent = new Intent(Intent.ACTION_SENDTO, mUri);
But it is not working. For this i googled alot. So please guide me how to do this. Is it possible to share particular recipant or not?
Thank you all..
The easiest way I know is by calling the following method (Use the String variable message to input the text you want to send via WhatAapp):
private void sendWhatsapp(String message){
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
}
I have a solution to send text only to a specific recipient. For sending an image to a specific recipient I am also using this.
String smsNumber = "Your specific contact No. here! ";
String msg = "Your message here!";
Uri uri = Uri.parse("http://api.whatsapp.com/send?phone="+smsNumber +"&text="+msg);
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
} catch(Exception e) {
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}

Share text OR Image On Whatsapp in Android

I am developing an application in which i have to share image and text on WhatsApp with in my application.
In IOS i have this code
NSURL *whatsappURL = [NSURL URLWithString:#"whatsapp://send?text=Hello%2C%20World!&abid=143rnjk4545352523"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
How i will be able to do this in Android?Is there any possiblity to share text and images on whatsapp from Android app?
You can use Whatsapp intent to do so.
Note :- WhatsApp does not support messages with both pictures and text,so use below code to share text.
Share Text on Whatsapp
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Hello World");
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
Share Image on Whatsapp
Intent whatsappIntent = new Intent(android.content.Intent.ACTION_SEND);
whatsappIntent.setType("image/*");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file));//add image path
startActivity(Intent.createChooser(share, "Share image using"));
Update
Whatsapp now support text (consider as image caption) with image as
Intent whatsappIntent = new Intent(android.content.Intent.ACTION_SEND);
whatsappIntent.setType("image/*");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Hello World");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); //add image path
startActivity(Intent.createChooser(share, "Share image using"));
try {
activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(activity, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
Currently Whatsapp supports Image and Text sharing at the same time. (Nov 2014).
Here is an example of how to do this:
/**
* Show share dialog BOTH image and text
*/
Uri imageUri = Uri.parse(pictureFile.getAbsolutePath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
It is Possible now for Whatsapp Chack your self.
As of Now Whatsapp Support share Image and text together.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT,title + "\n\nLink : " + link );
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sharePath));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share image via:"));
Image will be as it is and pass text as EXTRA_TEXT and it will be shown as caption.

Categories

Resources