Android SDK 2.3.0
From Social ID Developers
Revision as of 16:36, 8 October 2014 by Dirceu.tiegs (Talk | contribs)
Contents |
Download and Setup the SDK
You can download and setup the SDK using our Android SDK Setup guide.
Social Login
Add the following statements to your Activity:
import com.coffeebeantech.socialidsdk.SocialId; import com.coffeebeantech.socialidsdk.exceptions.SocialIdSDKException; import com.coffeebeantech.socialidsdk.util.Provider;
Add the following code to the end of the onCreate() method:
try { SocialId.configLogin(this, new LoginEventListenerImpl(this)); } catch (SocialIdSDKException e) { e.printStackTrace(); }
Add the following code to the end of the onActivityResult() method:
SocialId.onActivityResult(this, requestCode, resultCode, data);
Call the following code to make the user log in:
try { SocialId.initLogin(Provider.FACEBOOK); // you can change FACEBOOK to LINKEDIN, TWITTER or GPLUS } catch (SocialIdSDKException e) { e.printStackTrace(); }
Finally, create a LoginEventListenerImpl class using this example:
package com.YOUR_PACKAGE; import android.app.Activity; import android.content.Intent; import android.widget.Toast; import com.coffeebeantech.socialidapi.models.marketing.login.User; import com.coffeebeantech.socialidsdk.exceptions.SocialIdSDKException; import com.coffeebeantech.socialidsdk.sociallogin.LoginEventListener; import com.coffeebeantech.socialidsdk.util.Provider; public class LoginEventListenerImpl implements LoginEventListener { private Activity mActivity; private ProgressDialog mProgressDialog; public LoginEventListenerImpl(Activity activity) { this.mActivity = activity; } @Override public void onBack() { Toast.makeText(mActivity, "onBack", Toast.LENGTH_SHORT).show(); } @Override public void onCancel() { Toast.makeText(mActivity, "onCancel", Toast.LENGTH_SHORT).show(); } @Override public void onComplete(Provider provider, User loginUser) { Toast.makeText(mActivity, "onComplete", Toast.LENGTH_SHORT).show(); mActivity.startActivity(new Intent(mActivity, UserProfileActivity.class)); } @Override public void onError(SocialIdSDKException e) { Toast.makeText(mActivity, "onError", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } @Override public void onPreExecute() { Toast.makeText(mActivity, "onPreExecute", Toast.LENGTH_SHORT).show(); mProgressDialog = new ProgressDialog(mActivity); mProgressDialog.setCancelable(false); mProgressDialog.setTitle("Please wait"); mProgressDialog.setMessage("Loading ..."); mProgressDialog.show(); } @Override public void onPostExecute() { Toast.makeText(mActivity, "onPostExecute", Toast.LENGTH_SHORT).show(); mProgressDialog.dismiss(); } }
Logout
Use the following code to log out an user:
SocialId.logoutUser();
Get the user profile
Add the following statements to your Activity:
import com.coffeebeantech.socialidapi.models.marketing.database.PersonProfile; import com.coffeebeantech.socialidapi.models.marketing.login.User; import com.coffeebeantech.socialidsdk.SocialId;
Use the following code to get the user profile:
User mUser = SocialId.getCurrentUser(); if(mUser != null) { PersonProfile personProfile = mUser.getProfile(); // you can now call personProfile.getDisplayName(), personProfile.getPictureUrl() and other methods to get profile data }