I am using Login with FaceBook functionality for my Android app. in which I am facing an issue, with existing FaceBook app in device.
I am using SessionLoginSample for sign in with facebook. It is display one custom view for login with facebook and it is working fine but If there is facebook application installed in device then it will not display its custom view instead it navigate to facebook application and display its login page (or View. see below image ) and if I login in facebook app I am not getting proper response from facebook authentication process.
Facebook application login view
And if there is no facebook application installed in device then it will display its custom view and all whole flow for particular functionality is working fine.
SessionLoginSample's custom View
Is there any way to display SessionLoginSample's custom View always even if there is facebook application installed in device Or any alternative related this issue?
I've solved by this code section in my app. This will give response in both scenario, ie Native app is installed or it is not installed.
Here is a link for thi
import com.facebook.AsyncFacebookRunner;
import com.facebook.DialogError;
import com.facebook.Facebook;
import com.facebook.Facebook.DialogListener;
import com.facebook.FacebookError;
import com.facebook.Session;
import com.facebook.SessionState;
facebook = new Facebook( APP_ID );
mAsyncRunner = new AsyncFacebookRunner( facebook );
loginWithFB();
public void loginWithFB()
{
if(!facebook.isSessionValid()) {
facebook.authorize(Login.this, new String[] {"publish_stream","read_stream", "offline_access"}, //Facebook.FORCE_DIALOG_AUTH,
new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {Log.e("FB:","Facebook Error" );}
@Override
public void onError(DialogError e) {Log.e("FB:","Error" );}
@Override
public void onCancel() {}
});
}
}
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data )
{
super.onActivityResult( requestCode, resultCode, data );
facebook.authorizeCallback( requestCode, resultCode, data );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.