Integrate Linkedin, Facebook, Twitter, MySpace in Android App with One SDK


/ Published in: Java
Save to your folder(s)

The main objective of this example is to access social media providers Facebook, Twitter and others by clicking a single button "Share".On Clicking the button
the api will open dialog of providers. User can access the provider from dialog
and can update the status , get friends list , user profile


Copy this code and paste it in your HTML
  1. public class ShareButtonActivity extends Activity {
  2.  
  3. // SocialAuth Component
  4. SocialAuthAdapter adapter;
  5.  
  6. @Override
  7. public void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.main);
  10.  
  11. // Welcome Message
  12. TextView textview = (TextView)findViewById(R.id.text);
  13. textview.setText("Welcome to SocialAuth Demo. We are sharing text SocialAuth Android by share button.");
  14.  
  15. //Create Your Own Share Button
  16. Button share = (Button)findViewById(R.id.sharebutton);
  17. share.setText("Share");
  18. share.setTextColor(Color.WHITE);
  19. share.setBackgroundResource(R.drawable.button_gradient);
  20.  
  21. // Add it to Library
  22. adapter = new SocialAuthAdapter(new ResponseListener());
  23.  
  24. // Add providers
  25. adapter.addProvider(Provider.FACEBOOK, R.drawable.facebook);
  26. adapter.addProvider(Provider.TWITTER, R.drawable.twitter);
  27. adapter.addProvider(Provider.LINKEDIN, R.drawable.linkedin);
  28. adapter.addProvider(Provider.MYSPACE, R.drawable.myspace);
  29. adapter.enable(share);
  30.  
  31. }
  32.  
  33.  
  34. /**
  35. * Listens Response from Library
  36. *
  37. */
  38.  
  39. private final class ResponseListener implements DialogListener
  40. {
  41. /**
  42. *
  43. */
  44. private static final long serialVersionUID = 1L;
  45.  
  46. public void onComplete(Bundle values) {
  47.  
  48. // Variable to receive message status
  49. boolean status;
  50.  
  51. Log.d("ShareButton" , "Authentication Successful");
  52.  
  53. // Get name of provider after authentication
  54. String providerName = values.getString(SocialAuthAdapter.PROVIDER);
  55. Log.d("ShareButton", "Provider Name = " + providerName);
  56.  
  57. try
  58. {
  59. // Please avoid sending duplicate message. Social Media Providers block duplicate messages.
  60. adapter.getCurrentProvider().updateStatus("SocialAuth Android" + System.currentTimeMillis());
  61. status = true;
  62. }
  63. catch (Exception e)
  64. {
  65. status = false;
  66. }
  67.  
  68. // Post Toast or Dialog to display on screen
  69. if(status)
  70. Toast.makeText(ShareButtonActivity.this, "Message posted on " + providerName, Toast.LENGTH_SHORT).show();
  71. else
  72. Toast.makeText(ShareButtonActivity.this, "Message not posted on" + providerName, Toast.LENGTH_SHORT).show();
  73.  
  74. }
  75.  
  76. public void onError(SocialAuthError error) {
  77. Log.d("ShareButton" , "Authentication Error");
  78. }
  79.  
  80. public void onCancel() {
  81. Log.d("ShareButton" , "Authentication Cancelled");
  82. }
  83.  
  84. }
  85.  
  86. }

URL: http://code.google.com/p/socialauth-android/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.