Share of Whatsapp and facebook along with text and image - android

I wanted to share my image to social site along with textlink and image , I am using below code , it does share Image but no text , Also I tried to set setype to "text/html" , it does not does what i need.
protected void onPostExecute(String args) {
// TODO Auto-generated method stub
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_TITLE, "http://www.google.com");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(Intent.createChooser(share, "Share Image"));
pDialog.dismiss();
}

Give this a try
Uri imageUri = Uri.parse(Filepath);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, "My sample image 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("Kindly install whatsapp first");
}
PS: For sharing in multiple apps just create an alert dialogue and add
whtsapp,fb and other sharing option and while clicking on them you
have to call specific intent for this.As per my knowledge for sharing
in facebook you must impliment it's sdk, though facebook is able to
share simple image and hyperlink without integrating sdk.

Related

Unable to share image link via whatsapp

Actually I've given a share option in my app to share pictures to whatsapp by referring this link but it' not working . It's toasting something like Share failded please try again.Can anyone please help me to solve this issue.
Code:
String image_url = "http://images.cartradeexchange.com//img//800//vehicle//Honda_Brio_562672_5995_6_1438153637072.jpg";
Intent shareIntent = new Intent();
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, image_url);
// Target whatsapp:
shareIntent.setPackage("com.whatsapp");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(InventoryManageOnlineActivity.this,
"Whatsapp have not been installed.",
Toast.LENGTH_SHORT).show();
}
You are trying to share that URL as text. So use:
shareIntent.setType("text/plain");

Instagram sharing issue: Always I get the message “Unable to load image”

I'm working on share functionality
I 've a problem with Instagram Share
Here is my code :
I'm trying share "account" image which is stored in "drawable" folder.This is just an example
try {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse("android.resource://com.example.swathi.booklender/drawable/account");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
}catch (Exception e)
{
Toast.makeText(getActivity(),"No Activity available, install instagram",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
How to I get rid of this problem?
You can't share drawable directly
First create a file from drawable then share it
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
File image = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(shareIntent, "Share image via"));

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

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.

sharing photo from android app

I have developed one wallpaper application in which I want to add share button to share a photo on whatsapp. Here is my code( but that code is only for any text msg) I want to share a photo.
Please respond with the code where in I can select a wallpaper from my application and send to whatsapp's particular contact.
case R.id.save:
InputStream y11 = getResources().openRawResource(to);
Bitmap b11 = BitmapFactory.decodeStream(y11);
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("image/*");
waIntent.setPackage("com.whatsapp.android");
waIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, to);
startActivity(Intent.createChooser(waIntent, "Share with"));
Replace
waIntent.setType("text/plain");
with
waIntent.setType("image/png");
the package name is wrong. try: com.whatsapp
and this code is to share image via whatsapp
private void shareIt(Uri uri) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"Shared via my app");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "share with"));
}

Categories

Resources