Quantcast
Channel: Web and Android Development Tips
Viewing all articles
Browse latest Browse all 23

Android - Sharing text to Facebook, Twitter, and other Apps

$
0
0
Sharing on Android is extremely easy.

If you've ever hit a share button on the Android before, you'll notice most of them pop up a menu like this:


As you can see, this has the standard Google Apps as well as custom apps - like Facebook and some joke app I downloaded.

To share to other apps, you declare an Intent with the action "ACTION_SEND"


Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sharingIntent, "Share using"));


This will send plain text "Text" with the subject "Subject. It will pop up a chooser to select anything that has implemented an ACTION_SEND receiver for text.

One thing to note with the Facebook application: there's a bug!! It will show up blank if you have a link in your text unless you only send the link with nothing else.

Other types of note are: "application/twitter" and "text/html".

If you wish to create a "Twitter only" sharing button, check out this StackOverflow question - it answers that perfectly.

Viewing all articles
Browse latest Browse all 23

Trending Articles