Last active
February 25, 2019 09:22
-
-
Save shishirthedev/d770af494f3186b491e087a0be61d83b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FacebookAccountKitService { | |
public static FacebookAccountKitService shared = new FacebookAccountKitService(); | |
// Phone Login.................................................................... | |
public void phoneLogin(Context context,final int PHONE_LOGIN_CODE){ | |
final Intent phoneAuthIntent = new Intent(context, AccountKitActivity.class); | |
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder( | |
LoginType.PHONE, AccountKitActivity.ResponseType.TOKEN); | |
String[] smsWhitelist = new String[]{"BD"}; | |
configurationBuilder.setSMSWhitelist(smsWhitelist); | |
configurationBuilder.setDefaultCountryCode("BD"); | |
phoneAuthIntent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configurationBuilder.build()); | |
((AppCompatActivity)context).startActivityForResult(phoneAuthIntent, PHONE_LOGIN_CODE); | |
} | |
// Email Login..................................................................... | |
public void emailLogin(Context context, final int EMAIL_LOGIN_CODE){ | |
final Intent emailAuthIntent = new Intent(context, AccountKitActivity.class); | |
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfiguration.AccountKitConfigurationBuilder( | |
LoginType.EMAIL, AccountKitActivity.ResponseType.TOKEN); | |
emailAuthIntent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configurationBuilder.build()); | |
((AppCompatActivity)context).startActivityForResult(emailAuthIntent, EMAIL_LOGIN_CODE); | |
} | |
// Get Current Account Holder Phone/Email.......................................... | |
public void getCurrentAccountHolder(final GetCurrentAccountListener currentAccountListener){ | |
AccessToken fbKitAccessToken = AccountKit.getCurrentAccessToken(); | |
if (fbKitAccessToken != null) { | |
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() { | |
@Override | |
public void onSuccess(Account account) { | |
if (account.getPhoneNumber() != null) { | |
currentAccountListener.onSuccess(account.getPhoneNumber().toString()); | |
}else if (account.getEmail() != null){ | |
currentAccountListener.onSuccess(account.getEmail()); | |
} | |
} | |
@Override | |
public void onError(AccountKitError accountKitError) { | |
currentAccountListener.onError(accountKitError.getErrorType().getMessage()); | |
} | |
}); | |
} | |
} | |
// Account Kit Logout.............................................................. | |
public void logOut(){ | |
if(AccountKit.getCurrentAccessToken() != null){ | |
AccountKit.logOut(); | |
} | |
} | |
public interface GetCurrentAccountListener{ | |
void onSuccess(String accountHolder); | |
void onError(String errorMsg); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment