Android SDK 2.3.0

(Difference between revisions)
Jump to: navigation, search
(Logout)
Line 8: Line 8:
  
 
   import com.coffeebeantech.socialidsdk.SocialId;
 
   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:
 
Add the following code to the end of the onCreate() method:
  
   try {
+
   SocialId.configLogin(this, new LoginEventListenerImpl(this));
     SocialId.configLogin(this, new LoginEventListenerImpl(this));
+
 
   } catch (SocialIdSDKException e) {
+
If you want to pass additional configuration, such as the default user profile fields to get from the Social Id platform, you can use the following code instead. See [[Social Profile Fields]] for the available profile fields.
     e.printStackTrace();
+
 
   }
+
  import com.coffeebeantech.socialidsdk.sociallogin.SocialLoginConfiguration;
 +
 
 +
  SocialLoginConfiguration socialLoginConfiguration = new SocialLoginConfiguration().
 +
     setUserFields(Arrays.asList("display_name", "picture_url", "current_location", "verified_email", "gender"));
 +
 
 +
  SocialId.configLogin(this, new LoginEventListenerImpl(this), socialLoginConfiguration);
 +
 
 +
Additional configuration for each provider can also be given as the example below:
 +
 
 +
   import com.coffeebeantech.socialidsdk.sociallogin.providers.FacebookConfiguration;
 +
 
 +
  FacebookConfiguration facebookConfiguration = new FacebookConfiguration()
 +
     .setPermissions(Arrays.asList("public_profile", "user_birthday", "email", "user_location"));
 +
   SocialId.configLoginProvider(facebookConfiguration);
  
 
Add the following code to the end of the onActivityResult() method:
 
Add the following code to the end of the onActivityResult() method:
Line 25: Line 36:
 
Call the following code to make the user log in:
 
Call the following code to make the user log in:
  
 +
  import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 +
  import com.coffeebeantech.socialidsdk.util.Provider;
 +
 
 
   try {
 
   try {
 
     SocialId.initLogin(Provider.FACEBOOK); // you can change FACEBOOK to LINKEDIN, TWITTER or GPLUS
 
     SocialId.initLogin(Provider.FACEBOOK); // you can change FACEBOOK to LINKEDIN, TWITTER or GPLUS
   } catch (SocialIdSDKException e) {
+
   } catch (SocialIdException e) {
 
     e.printStackTrace();
 
     e.printStackTrace();
 
   }
 
   }
Line 33: Line 47:
 
Finally, create a LoginEventListenerImpl class using this example:
 
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.socialidapi.models.marketing.login.User;
   import com.coffeebeantech.socialidsdk.exceptions.SocialIdSDKException;
+
   import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 
   import com.coffeebeantech.socialidsdk.sociallogin.LoginEventListener;
 
   import com.coffeebeantech.socialidsdk.sociallogin.LoginEventListener;
 
   import com.coffeebeantech.socialidsdk.util.Provider;
 
   import com.coffeebeantech.socialidsdk.util.Provider;
 +
 
 
   public class LoginEventListenerImpl implements LoginEventListener {
 
   public class LoginEventListenerImpl implements LoginEventListener {
 +
 
 
     private Activity mActivity;
 
     private Activity mActivity;
    private ProgressDialog mProgressDialog;
+
 
 
     public LoginEventListenerImpl(Activity activity) {
 
     public LoginEventListenerImpl(Activity activity) {
 
       this.mActivity = activity;
 
       this.mActivity = activity;
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
 
     public void onBack() {
 
     public void onBack() {
       Toast.makeText(mActivity, "onBack", Toast.LENGTH_SHORT).show();
+
       // onBack code
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
 
     public void onCancel() {
 
     public void onCancel() {
       Toast.makeText(mActivity, "onCancel", Toast.LENGTH_SHORT).show();
+
       // onCancel code
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
     public void onComplete(Provider provider, User loginUser) {
+
     public void onComplete(Provider provider, User user) {
       Toast.makeText(mActivity, "onComplete", Toast.LENGTH_SHORT).show();
+
       // onComplete code
       mActivity.startActivity(new Intent(mActivity, UserProfileActivity.class));
+
       // PersonProfile personProfile = user.getProfile();
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
     public void onError(SocialIdSDKException e) {
+
     public void onError(SocialIdException e) {
       Toast.makeText(mActivity, "onError", Toast.LENGTH_SHORT).show();
+
       // onError code
 
       e.printStackTrace();
 
       e.printStackTrace();
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
 
     public void onPreExecute() {
 
     public void onPreExecute() {
       Toast.makeText(mActivity, "onPreExecute", Toast.LENGTH_SHORT).show();
+
       // onPreExecute code
      mProgressDialog = new ProgressDialog(mActivity);
+
      mProgressDialog.setCancelable(false);
+
      mProgressDialog.setTitle("Please wait");
+
      mProgressDialog.setMessage("Loading ...");
+
      mProgressDialog.show();
+
 
     }
 
     }
 +
 
 
     @Override
 
     @Override
 
     public void onPostExecute() {
 
     public void onPostExecute() {
       Toast.makeText(mActivity, "onPostExecute", Toast.LENGTH_SHORT).show();
+
       // onPostExecute code
      mProgressDialog.dismiss();
+
 
     }
 
     }
 
   }
 
   }
Line 85: Line 97:
 
Use the following code to log out a user:
 
Use the following code to log out a user:
  
 +
  import com.coffeebeantech.socialidsdk.SocialId;
 +
 
 
   SocialId.logoutUser();
 
   SocialId.logoutUser();
  
= Get the user profile =
+
= Get the logged user =
  
Add the following statements to your Activity:
+
Use the following code to get the current logged used in cache:
  
 
   import com.coffeebeantech.socialidapi.models.marketing.database.PersonProfile;
 
   import com.coffeebeantech.socialidapi.models.marketing.database.PersonProfile;
 
   import com.coffeebeantech.socialidapi.models.marketing.login.User;
 
   import com.coffeebeantech.socialidapi.models.marketing.login.User;
 
   import com.coffeebeantech.socialidsdk.SocialId;
 
   import com.coffeebeantech.socialidsdk.SocialId;
 +
 
 +
  User user = SocialId.getCurrentUser();
 +
  PersonProfile personProfile = user.getProfile();
 +
  // you can now call personProfile.getDisplayName(), personProfile.getPictureUrl() and other methods to get profile data
  
Use the following code to get the user profile:
+
If you want a refreshed user from the Social Id platform, you can use the following code instead:
  
   User mUser = SocialId.getCurrentUser();
+
   import com.coffeebeantech.socialidapi.models.marketing.login.User;
   if(mUser != null) {
+
  import com.coffeebeantech.socialidsdk.SocialId;
     PersonProfile personProfile = mUser.getProfile();
+
  import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
     // you can now call personProfile.getDisplayName(), personProfile.getPictureUrl() and other methods to get profile data
+
   import com.coffeebeantech.socialidsdk.util.SocialIdCallback;
 +
 
 +
  SocialId.getCurrentUser(new SocialIdCallback<User>() {
 +
     @Override
 +
    public void onSuccess(User user) {
 +
      // PersonProfile personProfile = user.getProfile();
 +
     }
 +
 
 +
    @Override
 +
    public void onError(SocialIdException e) {
 +
      e.printStackTrace();
 +
    }
 +
  });
 +
 
 +
= User Push Notifications =
 +
 
 +
In order to send push notifications directly to a specific user, you can link his device with his account. You can make this process whenever you want after the user logs in:
 +
 
 +
  import com.coffeebeantech.socialidsdk.SocialId;
 +
  import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 +
  import com.coffeebeantech.socialidsdk.util.SocialIdCallback;
 +
 
 +
  if(SocialId.getDeviceId() != null && !SocialId.getDeviceId().isEmpty()) {
 +
    SocialId.linkDeviceToUser(new SocialIdCallback<Void>() {
 +
      @Override
 +
      public void onSuccess(Void v) {
 +
        // onSuccess code
 +
      }
 +
 
 +
      @Override
 +
      public void onError(SocialIdException e) {
 +
        // onError code
 +
      }
 +
    });
 
   }
 
   }

Revision as of 19:11, 17 September 2015

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;

Add the following code to the end of the onCreate() method:

 SocialId.configLogin(this, new LoginEventListenerImpl(this));

If you want to pass additional configuration, such as the default user profile fields to get from the Social Id platform, you can use the following code instead. See Social Profile Fields for the available profile fields.

 import com.coffeebeantech.socialidsdk.sociallogin.SocialLoginConfiguration;
 
 SocialLoginConfiguration socialLoginConfiguration = new SocialLoginConfiguration().
   setUserFields(Arrays.asList("display_name", "picture_url", "current_location", "verified_email", "gender"));
 
 SocialId.configLogin(this, new LoginEventListenerImpl(this), socialLoginConfiguration);

Additional configuration for each provider can also be given as the example below:

 import com.coffeebeantech.socialidsdk.sociallogin.providers.FacebookConfiguration;
 
 FacebookConfiguration facebookConfiguration = new FacebookConfiguration()
   .setPermissions(Arrays.asList("public_profile", "user_birthday", "email", "user_location"));
 SocialId.configLoginProvider(facebookConfiguration);

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:

 import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 import com.coffeebeantech.socialidsdk.util.Provider;
 
 try {
   SocialId.initLogin(Provider.FACEBOOK); // you can change FACEBOOK to LINKEDIN, TWITTER or GPLUS
 } catch (SocialIdException e) {
   e.printStackTrace();
 }

Finally, create a LoginEventListenerImpl class using this example:

 import com.coffeebeantech.socialidapi.models.marketing.login.User;
 import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 import com.coffeebeantech.socialidsdk.sociallogin.LoginEventListener;
 import com.coffeebeantech.socialidsdk.util.Provider;
 
 public class LoginEventListenerImpl implements LoginEventListener {
 
   private Activity mActivity;
 
   public LoginEventListenerImpl(Activity activity) {
     this.mActivity = activity;
   }
 
   @Override
   public void onBack() {
     // onBack code
   }
 
   @Override
   public void onCancel() {
     // onCancel code
   }
 
   @Override
   public void onComplete(Provider provider, User user) {
     // onComplete code
     // PersonProfile personProfile = user.getProfile();
   }
 
   @Override
   public void onError(SocialIdException e) {
     // onError code
     e.printStackTrace();
   }
 
   @Override
   public void onPreExecute() {
     // onPreExecute code
   }
 
   @Override
   public void onPostExecute() {
     // onPostExecute code
   }
 }

Logout

Use the following code to log out a user:

 import com.coffeebeantech.socialidsdk.SocialId;
 
 SocialId.logoutUser();

Get the logged user

Use the following code to get the current logged used in cache:

 import com.coffeebeantech.socialidapi.models.marketing.database.PersonProfile;
 import com.coffeebeantech.socialidapi.models.marketing.login.User;
 import com.coffeebeantech.socialidsdk.SocialId;
 
 User user = SocialId.getCurrentUser();
 PersonProfile personProfile = user.getProfile();
 // you can now call personProfile.getDisplayName(), personProfile.getPictureUrl() and other methods to get profile data

If you want a refreshed user from the Social Id platform, you can use the following code instead:

 import com.coffeebeantech.socialidapi.models.marketing.login.User;
 import com.coffeebeantech.socialidsdk.SocialId;
 import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 import com.coffeebeantech.socialidsdk.util.SocialIdCallback;
 
 SocialId.getCurrentUser(new SocialIdCallback<User>() {
   @Override
   public void onSuccess(User user) {
     // PersonProfile personProfile = user.getProfile();
   }
 
   @Override
   public void onError(SocialIdException e) {
     e.printStackTrace();
   }
 });

User Push Notifications

In order to send push notifications directly to a specific user, you can link his device with his account. You can make this process whenever you want after the user logs in:

 import com.coffeebeantech.socialidsdk.SocialId;
 import com.coffeebeantech.socialidsdk.exceptions.SocialIdException;
 import com.coffeebeantech.socialidsdk.util.SocialIdCallback;
 
 if(SocialId.getDeviceId() != null && !SocialId.getDeviceId().isEmpty()) {
   SocialId.linkDeviceToUser(new SocialIdCallback<Void>() {
     @Override
     public void onSuccess(Void v) {
       // onSuccess code
     }
 
     @Override
     public void onError(SocialIdException e) {
       // onError code
     }
   });
 }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox