use of com.facebook.CallbackManager in project Android-SDK by Backendless.
the class LoginWithFacebookSDKActivity method configureFacebookSDKLogin.
private CallbackManager configureFacebookSDKLogin() {
loginFacebookButton.setReadPermissions("email");
// If using in a fragment
// loginFacebookButton.setFragment(this);
CallbackManager callbackManager = CallbackManager.Factory.create();
// Callback registration
loginFacebookButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
isLoggedInFacebook = true;
fbAccessToken = loginResult.getAccessToken().getToken();
String msg = "ApplicationId: " + loginResult.getAccessToken().getApplicationId() + "\n" + "UserId: " + loginResult.getAccessToken().getUserId() + "\n" + "Token: " + loginResult.getAccessToken().getToken() + "\n" + "LastRefresh: " + loginResult.getAccessToken().getLastRefresh().toString() + "\n" + "Expires: " + loginResult.getAccessToken().getExpires().toString();
socialAccountInfo.setTextColor(getColor(android.R.color.black));
socialAccountInfo.setText(msg);
if (!isLoggedInBackendless)
loginToBackendless();
else
loginFacebookButton.setVisibility(View.INVISIBLE);
fbLogoutBackendlessButton.setVisibility(View.VISIBLE);
}
@Override
public void onCancel() {
// App code
Log.i("LoginProcess", "loginFacebookButton::onCancel");
}
@Override
public void onError(FacebookException exception) {
fbAccessToken = null;
String msg = exception.getMessage() + "\nCause:\n" + (exception.getCause() != null ? exception.getCause().getMessage() : "none");
socialAccountInfo.setTextColor(getColor(android.R.color.holo_red_dark));
socialAccountInfo.setText(msg);
isLoggedInFacebook = false;
}
});
return callbackManager;
}
use of com.facebook.CallbackManager in project CodenameOne by codenameone.
the class FacebookImpl method login.
private void login(final LoginCallback cb) {
if (loginLock) {
return;
}
loginLock = true;
LoginManager login = LoginManager.getInstance();
final CallbackManager mCallbackManager = CallbackManager.Factory.create();
if (AndroidNativeUtil.getActivity() == null) {
throw new RuntimeException("Cannot login to facebook when running in the background.");
}
final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
activity.setIntentResultListener(new IntentResultListener() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
activity.restoreIntentResultListener();
}
});
login.registerCallback(mCallbackManager, new FBCallback(cb));
login.logInWithReadPermissions(activity, permissions);
}
use of com.facebook.CallbackManager in project CodenameOne by codenameone.
the class FacebookImpl method inviteFriends.
@Override
public void inviteFriends(String appLinkUrl, String previewImageUrl, final Callback cb) {
if (AndroidNativeUtil.getActivity() == null) {
throw new RuntimeException("Cannot invite friends while running in the background.");
}
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder().setApplinkUrl(appLinkUrl).setPreviewImageUrl(previewImageUrl).build();
final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
if (cb == null) {
AppInviteDialog.show(activity, content);
} else {
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
final CallbackManager mCallbackManager = CallbackManager.Factory.create();
activity.setIntentResultListener(new IntentResultListener() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
activity.restoreIntentResultListener();
}
});
appInviteDialog.registerCallback(mCallbackManager, new FacebookCallback<AppInviteDialog.Result>() {
@Override
public void onSuccess(AppInviteDialog.Result result) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onSucess(null);
}
});
}
@Override
public void onCancel() {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onError(null, null, -1, "User Cancelled");
}
});
}
@Override
public void onError(final FacebookException e) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onError(null, e, 0, e.getMessage());
}
});
}
});
appInviteDialog.show(content);
}
}
}
use of com.facebook.CallbackManager in project CodenameOne by codenameone.
the class FacebookImpl method askPublishPermissions.
public void askPublishPermissions(final LoginCallback cb) {
if (AndroidNativeUtil.getActivity() == null) {
throw new RuntimeException("Cannot ask for publish permissions when running in the background.");
}
if (loginLock) {
return;
}
loginLock = true;
LoginManager login = LoginManager.getInstance();
final CallbackManager mCallbackManager = CallbackManager.Factory.create();
final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
activity.setIntentResultListener(new IntentResultListener() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
activity.restoreIntentResultListener();
}
});
login.registerCallback(mCallbackManager, new FBCallback(cb));
login.logInWithPublishPermissions(activity, PUBLISH_PERMISSIONS);
}
Aggregations