简体   繁体   中英

Auto sign in with Google, Facebook and Twitter in Android App

Actually I have 2 questions. I added google, facebook and twitter sign in to my android app. I use firebase sign in for register and login. After that I will use my own python server. Now, I want to add auto sign in. Namely, after first login, it won't show login page again and it will open other pages automatically. I searched but i didn't find a sample for this structure. How can I do auto sign in with facebook, google, twitter in my android app. And how my server know this login is success and it will give user's data to clients in securely.

You need to do a web-service call from Android side just after login from firebase, stating in your server that this user has logged in to your app. You can store the access token provided by firebase or you can generate yours on web service call and thereby authenticate user with that token for user specific pages.

When the user first logged in you need to save a Boolean shared preference states that the user is already logged in every time you need to check if the user is logged in before showing the login screen.

  public void saveIsLoggedIn(Context context, Boolean isLoggedIn){
    mContext = context;
    sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean ("IS_LOGGED_IN", isLoggedIn);
    editor.commit();

}

public boolean getISLoggedIN() {
    //mContext = context;
    sharedPreferences = mContext.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
    return sharedPreferences.getBoolean("IS_LOGGED_IN", false);

}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM