Saturday, March 17, 2012

Android: Sharing Facebook, Twitter, E-mail

Okay, there are tutorials out there just as much as Justin Bieber fans...hmmm...is that a little or a lot?? Anyway, here we gooo!!!

Sharing E-mail
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle);
intent.putExtra(android.content.Intent.EXTRA_TEXT, mMessage);
startActivity(Intent.createChooser(intent, "Title of E-mail Chooser Dialog"));

Sharing Twitter
Use "https://twitter.com/intent/tweet?text="
You can append a string right after. So far appending this formats things correctly:
URLEncoder.encode(mMessage,"UTF-8")

So your string looks like:
"https://twitter.com/intent/tweet?text="+URLEncoder.encode(mMessage,"UTF-8")

Sharing Facebook
Then most annoying sharing method if you plan to set a pre-made text in your app.

- Download the SDK and extract the folder you need (One with project files :\ )
- Create existing project with the Facebook stuff.
- Make sure it's a library. Go to Project Properties->Android, and check mark isLibrary
- Now add the library to your current project.
- Now you need to make a facebook activity. So create FacebookActivity!!!

- To create a preview message, implement it yourself. You can use a dialog or something. But you can directly post your message to your wall. Here's the code:

facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");

- There's a lot more code in the activity, but you can just visit here:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/

Happy days!!!!

No comments:

Post a Comment