Very often, you might want to enable the ability for users to share some content (either text, link or an image) from your Android app. Users can share the content using email, twitter, Facebook, sms or through numerous other ways.
The users might already have installed some custom apps for each one of the above service. So instead of coding all these again, it would be really nice (for both your users as well as for you as a developer) if you can invoke any one of these apps, where users want to share content from your app.
Sharing text
Android provides a built-in Intent called ACTION_SEND for this purpose. Using it in your app is very easy. All you have to do is to use the following couple of lines.
In my phone, it invokes the following dialog box listing the apps that have registered to get notification for this intent.
Sharing binary objects (Images, videos etc.)
In addition to supporting text, this intent also supports sharing images or any binary content. All you have to do is to set the appropriate mime type and then pass the binary data by calling the putExtra method.
Registering for the Intent
If you want your app to be listed when this Intent is called, then you have to add an intent filter in your manifest.xml file
android:mimeType
specifies the mime type which you are interested in listening.
Happy sharing 😉
Hi,
Thank you for this tuto, it’s very clear.
My problem is I don’t know java…
I’m using App Inventor to create my applications,
as a newbie I’m struggling to find out a way to call the sharing list which is exactly what you are describing here, but it seems that no one knows (or at least shares) yet how to do it in AI (apparently with “activity starter” component but how?).
Would it be possible for you to give us some ideas ? That would be much appreciated for us as AI users.
I am not sure if this can be done using App Inventor.
Thanks, amazing information!
So if I wanted to sent an array of binary bytes, what would the appropriate mime type be?
Hi all,
Thanks for this useful guidelines. Am new to this Android application coding. I need a small favor, actually out of those items “Facebook, Gmail, Mail, Messages and Peep”. is it possible to display only “Facebook, Gmail”. I need answer for this very much in urgent, Kindly do help me out in this. Thanks in advance
Raghu,
This will list down all applications that have registered to receive that Intend. If you need only a few, then you may have to implement the entire menu yourself as part of your application.
Share your adventures, photos with Gowalla Android app.
http://bstdownload.com/reviews/gowalla-3/
hi Sudar,
thanks for sharing your knowledge.
How can we copy and paste like functionality for Images.
Using ClipBoard we can copy text that I know.
pls suggest me way to do this.
thanks lot
Hello
I had used your app and able to launch Sharing Screen as you shown but it is not working means[Functionality].
Like selecting Bluetooth its able to Scan Device but not getting connected.
Any help
Check your error log and let me know if you are getting any exceptions there.
Hi, I want show the HTML file on facebook wall and did the same as above but the share option menu showing only mail, gmail and bluetooth. It’s not showing facebook or other options.
Note: I have included the code in menifest too.
Thanks
Do you have any Facebook app installed in your phone or emulator?
Yes, I have already installed facebook app for android. Thanks
for setType(“text/html”) facebook app is not showing in list. And if i user “text/plain” facebook twitter apps shows. But in facebook my data has not been sent and blank string will display in facebook app.
Any help will be appreciated. I want to send message in facebook app.
It seems that only urls can be shared in facebook, your texts does not appear.
Facebook doesn’t allow text to be shared directly. In order to do that you have to incorporate the Facebook SDK also.
Thanks for the article.
It turns Sharing content in Android is easy.
Thanks a lot….superb code
Thanks a lot for the post, but the code opens up a text editor on my device. Any suggestions on what am missing out?
> If you want your app to be listed
Listed?
Listed where?
And why would I want (or not want) this optional “listed” thing?
hi i am d learner….plz mail d code… Were i wll get this code to download……..
@Carol: Listed in the list of applications which are displayed if an sharing intent is triggered.
Hi all,
Thanks for this useful guidelines. Am new to this Android application coding. I need a small favor, actually out of those items “Facebook, Gmail, Mail, Messages and Peep”. is it possible to display only “Facebook, Gmail”. Kindly do help me out in this. Thanks in advance
Neeraj,
That’s not possible, since Android builds this list based on the list of apps that are installed in the phone.
i want to do when data share by intent using above code then how i receive data shared by intent. any one help me
how i get data shared by intent using broadcast receiver???
hi,
i want to create a new app,here the main thing is to share the images.
It has the online chatting feature so whille chatting i want to share images
to a perticular online member.Please give me some idea about this.
Thanks in advance.
This is very useful, thanks!
After trying this code, i was able to embed sharing, but the SMS option (Messaging) did not appear.
What’s the trick ?
hello. can I do this share list in php?
You can’t run PHP code in Android.
You not understand me.
I’m want to run this code in front-end of wordpress site.
Is it possible?
No it is not possible. This is an Android app code which can only run in an Android device.
you mention a possibility of sharing a link, but your example doesnt feature code explaining how to do link sharing. is it just a case of checking the “sent text” to see if it is a URL somehow or is there a specific intent filter for dealing with links/urls?
You might also have to change the mime:type.
Its HelpFull But I have Confuse Where I can Start.When i Click menu button show options menu in that share option select show the dialog what shown above how to integrate all in to my application please provide the step by step process for sharing image .
not working on facebook and linkedin,whtasapp, viber etc.
only working in email/gmail
Sharing an image (binary object) only works if the image is stored on the sd card (not in getFilesDir() oder getCacheDir() directories)! Otherwise there’s an error saying “could not add image to your message” (if shared with a messaging service).
hi how can i share to facebook only ?
hii iam developing android application using phone gap. Iam struggling to add native Share in my application.. can u help me how to add ACTION_SEND code in Phone Gap?? is it possible?? thanks in advance
well i looking for sharing data between two devices using share intent. is it possible kindly reply ASAP
Thanks in Advance
yeeeeaaaaah
Please tell me how to add images that are from drawable folder to alertdialog using java… thank you sir for your support
Thanks for this information actually i was making an android app for New year, in that i want to share, SMS and greetings using facebook, twitter and whatsapp.. Thanks using this article i am able to do it, Actually i have made my app on App inventor. But the intent commands have helped me a lot to do what i decided with my app. 🙂
i use the uri is Uri.parse(“android.resource://” + getPackageName()
+ “/drawable/” + “p1”)
HI
All things work only facebook not share the text content.
I think it looks like it is helpful. I thank you for that, but it has lack of details to new developers like me. Anyways, after I tried what you showed us, it worked 60%, so I had to Google in stackoverflaw and I found this that helped me solving 40% of my problems. Here is the code:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType(“text/plain”);
String shareBody = “This is a test”;
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “You have to see this!”);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivityForResult(Intent.createChooser(sharingIntent, “Share via”),1);
getFragmentManager().popBackStack();
Source for the code: http://stackoverflow.com/questions/12707427/android-sharing-something-via-intent-action-send-then-automatically-return-t
Viber not send image ..
bellow is my code:
Intent share_Intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
share_Intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
selectedList);
share_Intent.setType(“image/jpeg”);
share_Intent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(Intent.createChooser(share_Intent,
“Share_image_using”));
its not working for viber
Its not working for viber Image Sharing :
Image not Load when we share image in viber
I Solved the Problem of Viber photo sharing :
***********************************************************************
Please Refer Bellow code Guys
***********************************************************************
case R.id.action_Share:
selectedList = new ArrayList();
for (int i = 0; i < selected.size(); i++) {
if (selected.valueAt(i)) {
String file = mImageList.get(selected.keyAt(i));
selectedList.add(Uri.parse("file://"+file));
}
}
Intent share_Intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
share_Intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
selectedList);
share_Intent.setType("image/*");
setResult(Activity.RESULT_OK ,share_Intent);
share_Intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(share_Intent,
"Share_image_using"));
break;
}
***********************************************************************
put uri path like this : selectedList.add(Uri.parse("file://"+file));
***********************************************************************
great, thanks!
Hii,
I am having an error sharing text,
error log says: Are you missing a call to unragister reciever…!!!
I am learning fresh, can anyone tell what am i missing here??
Log Cat Says:
“01-08 19:39:10.839: E/ActivityThread(17216): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@418b4fa0 that was originally registered here. Are you missing a call to unregisterReceiver()?”
Regards
Manish
Can you post the part of your source code where you are getting this error in pastebin or gist.github.com and then post a link here?
I did it.
Thanx
Hi,
I am not seeing facebook, messenger, whatsapp in the options when I use this code even though the apps are installed in my mobile. Any idea why this is the case?
Sir I want to send a 3 sec sound on intent.. How could I do it using intent.. What should I write in put extras method.. Need help.. Wat should I write in set type.
Thanks are very beautiful and practical
You fail to tell which file and where in that file these pieces of code are to be placed.
The code goes into your Activity classes.
Thanks ….. It was very good
Mobile click-to-call functionality is a great way to capture call data without needing a special tracking number
way to capture call data without needing a special tracking number
Hi Sudar,
I am trying to send an image file from one android phone to another phone using bluetooth. My requirement is to send a specified file to specified devices only. I don’t want any user interaction in between. I am using action_send intent and pls find below the code. The problem I am getting is that it is displays the list of devices and expect me to select a bluetooth device and t he specified file is transferred. I am struggling to find a solution for the last 3 weeks and any help would be much appreciated.
code:
File f = new File(Environment.getExternalStorageDirectory(),”test1.jpg”);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setType(“image/*”);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
sendIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device.getAddress());
// sendIntent.setClassName(“com.android.bluetooth”, “com.broadcom.bt.app.opp.OppLauncherActivity”);
//sendIntent.setClassName(“com.android.bluetooth”, “com.android.bluetooth.opp.BluetoothOppLauncherActivity”);
sendIntent.setPackage(“com.android.bluetooth”);
startActivity(sendIntent);
and my manifest file looks:
Hello Moorthi,
Some of your code got truncated.
Can you post about this in Stackoverflow?
Hi,
Were you able to do that finally? Now I am struggling with the same problem…
Hi
I want to share some let you edit text. Code share one of them I know, but I do not know what I have to share all edited text. Sharing a text editing field codes tell me.
Thanks
plz send m the code of:
how to share a transport app on the click of list view..
only transport application
How do you make that pop-up menu (The one in the image) come up?
Intent intent=new Intent();
Uri screenshotUri =Uri.parse(“android.resource://com.example.pddlaptophp.freindsquits/”+ back[inm[k]]);
//back[inm[k]] its array location store image
intent.setAction(Intent.ACTION_SEND);
ssintent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
ssintent.setType(“image/png”);
startActivity(Intent.createChooser(ssintent, “share image “));
share only massenger like whatsapp,linkdin.etc
not share gmail,Bluetooth,facebook
plz— help
Hi
I want to share a page from one user to another user of my app.Both users will get registered with my app and one of them should be able to share a page to another by using internet.I am a newbie..Please help
Thanks
Hi where can i find the complete code for this.
I want to share a contact through whatsapp, I used this code but nothing seems to work can you please help me?
Intent i = new Intent();
i.setType(“text/x-vcard”);
i.setAction(Intent.ACTION_SEND);
startActivity(Intent.createChooser(i,”Share via”));
break;
This way used to work for me, but not for all apps, whatsapp shows me messege “file format is not supported” is there another way?
Sharing Binary objects(Images , videos etc)
I am stuck up in “path” within Uri which path should i give.please help…
easily understandable
Thanks a lot….superb code
Not showing Instagram app. Please help.
Thanks a lot….superb code
it is not working for me.it says “No apps can perform this action”
I need help, urgently. Just started programming in android I need to make an app that opens have the file explorer the user choose the file and share it through bluetooth that should be in the application part of the bluetooth are complicating me please someone who can help me I can send real email code who can help me please?
hello please reply me fast tell me that what path should i give to URI.parse(path) for uploading image to facebook etc. please help me
I need help, urgently. Just started programming in android I need to make an app that opens have the file explorer the user choose the file and share it through bluetooth that should be in the application part of the bluetooth are complicating me please someone who can help me I can send real email code who can help me please?
thanks for sharing this code. I was looking for it from a long time. thanks a lot professor.
Please help me to send a MMS using intent and other way.
Thanks
Very useful information discussed using well-researched facts and figures. Keep up the good work!