I'm using this for my Facebook
log-in and sharing. I'm wondering if instead of opening a WebView
that displays the log-in with Facebook
is there a way when a User have already installed a Facebook app
instead of opening the WebView
it will opens the Facebook app
? And when the User is already log-in in the Facebook App
it will gets its credentials and log-in automatically in my app
? I can't seem to find how to do this. Thank you in advantage.
Edit
I found out that my activityCode
always return -1 instead of >= 0 that's why it always open the WebView
instead of the app. And also found out that I need to enabled the Single Sign-On
, I enabled the Single Sign-On but it still doesn't open the facebook app
. Maybe it is because of FORCE_DIALOG_AUTH
that always returns -1
. I'm wondering if there is a default value instead of using FORCE_DIALOG_AUTH
.
In solution on the FORCE_DIALOG_AUTH
I used code below:
Instead of using
facebook.authorize(this, Constants.FACEBOOK_PERMISSIONS,
Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
I used
facebook.authorize(this, Constants.FACEBOOK_PERMISSIONS, new LoginDialogListener());
where in my Facebook.java
public void authorize(Activity activity, String[] permissions,
final DialogListener listener) {
authorize(activity, permissions, DEFAULT_AUTH_ACTIVITY_CODE, listener);
}
Also it detects now if there is an Facebook app
installed or not, but when there is an Facebook app
installed it still doesn't display/open in Facebook app
, it just load and goes back to my Activity nothing happens.
Update
I tried to log in without a user log-in in the Facebook app
and that user is still not authorized to use my app, it opens the Facebook app
log-in screen but after authorizing it, it doesn't get my log-in informations.
Here's my code in Facebook.java
it same as it is
private boolean startSingleSignOn(Activity activity, String applicationId,
String[] permissions, int activityCode) {
boolean didSucceed = true;
Intent intent = new Intent();
intent.setClassName("com.facebook.katana",
"com.facebook.katana.ProxyAuth");
intent.putExtra("client_id", applicationId);
if (permissions.length > 0) {
intent.putExtra("scope", TextUtils.join(",", permissions));
}
// Verify that the application whose package name is
// com.facebook.katana.ProxyAuth
// has the expected FB app signature.
if (!validateActivityIntent(activity, intent)) {
return false;
}
mAuthActivity = activity;
mAuthPermissions = permissions;
mAuthActivityCode = activityCode;
try {
activity.startActivityForResult(intent, activityCode);
} catch (ActivityNotFoundException e) {
didSucceed = false;
}
return didSucceed;
}
In my activity that calls the authorizing and handles what to do after authorizing here's my code
private void setFacebookConnection() {
// progressBar.setVisibility(View.VISIBLE);
facebook = new Facebook(Constants.FACEBOOK_APP_ID);
facebookAsyncRunner = new AsyncFacebookRunner(facebook);
// facebook.authorize(MerchantDetailsActivity.this, Constants.FACEBOOK_PERMISSIONS, // Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
facebook.authorize(MerchantDetailsActivity.this, Constants.FACEBOOK_PERMISSIONS, new LoginDialogListener());
}
private class LoginDialogListener implements Facebook.DialogListener {
public void onComplete(Bundle values) {
String token = facebook.getAccessToken();
long token_expires = facebook.getAccessExpires();
Log.d(TAG, "AccessToken: " + token);
Log.d(TAG, "AccessExpires: " + token_expires);
facebookSharedPreferences = PreferenceManager
.getDefaultSharedPreferences(context);
facebookSharedPreferences.edit()
.putLong(Constants.FACEBOOK_ACCESS_EXPIRES, token_expires)
.commit();
facebookSharedPreferences.edit()
.putString(Constants.FACEBOOK_ACCESS_TOKEN, token).commit();
facebookAsyncRunner.request("me", new IDRequestListener());
shareFBPost();
}
It seems that when the user is already authorized it doesn't go inside my LoginDialogListener