Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:24:30+00:00 2026-06-06T22:24:30+00:00

I have a facebook login option in my android application. When there is no

  • 0

I have a facebook login option in my android application.

When there is no Facebook application installed on my device, this login works fine. But when the facebook application is installed, it creates problems in a few cases.

So, how can I tell my application’s facebook login to ignore if Facebook app is installed and proceed in the previous way (assuming facebook application is not installed)?

This is the activity called when i click the fbLoginButton:

public class Example extends Activity {

    public static final String APP_ID = myAppIdHere;


    private LoginButton mLoginButton;
    private TextView mText;
    private Button mRequestButton;
    private Button mPostButton;
    private Button mDeleteButton;
    private Button mUploadButton;
    public static Activity ExampleActivity;

    private Facebook mFacebook;
    private AsyncFacebookRunner mAsyncRunner;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ExampleActivity = this;
        if (APP_ID == null) {
            Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " +
                    "specified before running this example: see Example.java");
        }

       setContentView(R.layout.facebook);
        mLoginButton = (LoginButton) findViewById(R.id.login);
        mFacebook = new Facebook(APP_ID);
        mAsyncRunner = new AsyncFacebookRunner(mFacebook);

        SessionStore.restore(mFacebook, this);
        SessionEvents.addAuthListener(new SampleAuthListener());
        SessionEvents.addLogoutListener(new SampleLogoutListener());
        mLoginButton.init(this, mFacebook);

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {

        mFacebook.authorizeCallback(requestCode, resultCode, data);
    }

    public class SampleAuthListener implements AuthListener {

        public void onAuthSucceed() {

        }

        public void onAuthFail(String error) {

        }
    }

    public class SampleLogoutListener implements LogoutListener {
        public void onLogoutBegin() {

        }

        public void onLogoutFinish() {

    }
}

This is LoginButton Class:

public class LoginButton extends ImageButton {

    public static Facebook mFb;
    public static String facebookID;
    public static String firstName;
    public static String lastName;
    public static String email = "";
    public static String sex;
    private Handler mHandler;
    private SessionListener mSessionListener = new SessionListener();
    private String[] mPermissions = new String[] { "read_stream", "email" };
    private Activity mActivity;

    public LoginButton(Context context) {
        super(context);
    }

    public LoginButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LoginButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void init(final Activity activity, final Facebook fb) {
        init(activity, fb, new String[] {});
    }

    public void init(final Activity activity, final Facebook fb,
            final String[] permissions) {
        mActivity = activity;
        mFb = fb;
        mPermissions = new String[] { "read_stream", "email" };
        ;
        mHandler = new Handler();

        setBackgroundColor(Color.TRANSPARENT);
        setAdjustViewBounds(true);

        if(mFb.isSessionValid()){
            getUser();
            SessionEvents.onLogoutBegin();
            AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFb);
            asyncRunner.logout(getContext(), new LogoutRequestListener());
        }else{

            setImageResource(R.drawable.login_button);
            drawableStateChanged();
        }

        SessionEvents.addAuthListener(mSessionListener);
        SessionEvents.addLogoutListener(mSessionListener);
        setOnClickListener(new ButtonOnClickListener());
    }

    private final class ButtonOnClickListener implements OnClickListener {

        public void onClick(View arg0) {
            if (mFb.isSessionValid()) {
                getUser();
                SessionEvents.onLogoutBegin();
                AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFb);
                asyncRunner.logout(getContext(), new LogoutRequestListener());
            } else {
                mFb.authorize(mActivity, mPermissions,
                        new LoginDialogListener());
            }
        }
    }

    private final class LoginDialogListener implements DialogListener {
        public void onComplete(Bundle values) {

            SessionEvents.onLoginSuccess();
        }

        public void onFacebookError(FacebookError error) {

            SessionEvents.onLoginError(error.getMessage());
        }

        public void onError(DialogError error) {

            SessionEvents.onLoginError(error.getMessage());
        }

        public void onCancel() {

            SessionEvents.onLoginError("Action Canceled");
        }

    }

    private class LogoutRequestListener extends BaseRequestListener {
        public void onComplete(String response, final Object state) {

            mHandler.post(new Runnable() {
                public void run() {

                SessionEvents.onLogoutFinish();
                }
            });
        }
    }

    private class SessionListener implements AuthListener, LogoutListener {

        public void onAuthSucceed() {

            setImageResource(R.drawable.logout_button);
            SessionStore.save(mFb, getContext());
        }

        public void onAuthFail(String error) {
        }

        public void onLogoutBegin() {
        }

        public void onLogoutFinish() {

            SessionStore.clear(getContext());
            setImageResource(R.drawable.login_button);
        }
    }

    public static void getUser() {

        try {
            JSONObject json = Util.parseJson(mFb.request("me"));
            facebookID = json.getString("id");
            firstName = json.getString("first_name");
            lastName = json.getString("last_name");
            email = json.getString("email");
            sex = json.getString("gender");
            String mFirstName = firstName;
            String mLastName = lastName;
            String mEmail = email;
            String mSex = sex;
            Log.d("User Details", "You are logged in : " + facebookID
                    + mFirstName + "." + mLastName + "  Email is: " + mEmail
                    + "-" + mSex);

            SharedPreferences.Editor editor = SignUpActivity.settings.edit();

            // Set "hasLoggedIn" to true
            editor.putBoolean("hasLoggedIn", true);
            editor.putString("fbEmail", email);
            editor.putString("fbId", facebookID);
            editor.putString("fbSex", sex);
            editor.putString("fbFirstname", firstName);
            editor.putString("fbLastname", lastName);

            // Commit the edits!
            editor.commit();
        } catch (Exception e) {
            // TODO: handle exception
            Log.d("Exception in getUser", "+++++" + e.toString());
        }
    }
}

This is SessionEvents Class:

public class SessionEvents {

    private static LinkedList<AuthListener> mAuthListeners = new LinkedList<AuthListener>();
    private static LinkedList<LogoutListener> mLogoutListeners = new LinkedList<LogoutListener>();

    public static void addAuthListener(AuthListener listener) {

        mAuthListeners.add(listener);
    }

    public static void removeAuthListener(AuthListener listener) {

        mAuthListeners.remove(listener);
    }

    public static void addLogoutListener(LogoutListener listener) {

        mLogoutListeners.add(listener);
    }

    public static void removeLogoutListener(LogoutListener listener) {

        mLogoutListeners.remove(listener);
    }

    public static void onLoginSuccess() {

        LoginButton.getUser();
        for (AuthListener listener : mAuthListeners) {
            listener.onAuthSucceed();
        }
    }

    public static void onLoginError(String error) {

        for (AuthListener listener : mAuthListeners) {
            listener.onAuthFail(error);
        }
    }

    public static void onLogoutBegin() {

        for (LogoutListener l : mLogoutListeners) {
            l.onLogoutBegin();
        }
    }

    public static void onLogoutFinish() {

        for (LogoutListener l : mLogoutListeners) {
            l.onLogoutFinish();
        }
    }

    public static interface AuthListener {

        public void onAuthSucceed();

        public void onAuthFail(String error);
    }

    public static interface LogoutListener {

        public void onLogoutBegin();

        public void onLogoutFinish();
    }

}

This is SessionStore class:

public class SessionStore extends Activity{

    private static final String TOKEN = "access_token";
    private static final String EXPIRES = "expires_in";
    private static final String KEY = "facebook-session";

    public static boolean save(Facebook session, Context context) {

        Context contextObj = Example.ExampleActivity;
        Intent i=new Intent(contextObj , SignUpActivity.class);
        contextObj.startActivity(i);

        Editor editor =
            context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.putString(TOKEN, session.getAccessToken());
        editor.putLong(EXPIRES, session.getAccessExpires());
        return editor.commit();
    }

    public static boolean restore(Facebook session, Context context) {

        SharedPreferences savedSession =
            context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
        session.setAccessToken(savedSession.getString(TOKEN, null));
        session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
        return session.isSessionValid();
    }

    public static void clear(Context context) {

        Editor editor = 
            context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();
    }

}

This is BaseRequestListener class:

public abstract class BaseRequestListener implements RequestListener {

    public void onFacebookError(FacebookError e, final Object state) {
        Log.e("Facebook", e.getMessage());
        e.printStackTrace();
    }

    public void onFileNotFoundException(FileNotFoundException e,
            final Object state) {
        Log.e("Facebook", e.getMessage());
        e.printStackTrace();
    }

    public void onIOException(IOException e, final Object state) {
        Log.e("Facebook", e.getMessage());
        e.printStackTrace();
    }

    public void onMalformedURLException(MalformedURLException e,
            final Object state) {
        Log.e("Facebook", e.getMessage());
        e.printStackTrace();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:24:32+00:00Added an answer on June 6, 2026 at 10:24 pm

    Please update below code of your Login Button Click listener.

    mFb.authorize(mActivity, mPermissions, Facebook.FORCE_DIALOG_AUTH,
                new LoginDialogListener());
    

    instead of

    mFb.authorize(mActivity, mPermissions, new LoginDialogListener());
    

    And see below link for more information

    Facebook Login Issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so i have this facebook login button: <fb:login-button autologoutlink=true onlogin=Log.info('onlogin callback')> </fb:login-button> but then
I have facebook login setup in my android app. When the user clicks login
I have read many questions about the facebook login but until not I didnt
My app should implement login with facebook but I have noticed that every time
I have some problem to setup application on facebook, ok what is exactly problems?
I have integrated Facebook login into my site(codeigniter).I got name, profile URL etc ..but
I have a Facebook connect site and am having issues with the Facebook login
I am trying to make a Facebook login in my website, I have faced
I have native facebook app in development for few months and login worked on
i have created a forum using php/mysql and users login through facebook using php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.