How do I check if the user has logged in once?

0

When the user presses the "login with facebook" button for the first time, the application asks for permission and returns the "Gave" dialog, but if I move and try to log in again error appears, then I have to delete the permission in the application to be able to do it again, how do I check if the user has already registered once?

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.AccessToken;
import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;

public class LoginFacebook extends Fragment {

    private LoginButton loginButton;
    private CallbackManager callbackManager;
    private AccessTokenTracker accessTokenTracker;
    private AccessToken accessToken;
    private Fragment1 fragment1;

    @Override
    public View onCreateView(
            LayoutInflater inflater,
            ViewGroup container,
            Bundle savedInstanceState) {
        FacebookSdk.sdkInitialize(getContext());

        callbackManager = CallbackManager.Factory.create();
        final View view = inflater.inflate(R.layout.loginfacebook, container, false);


        loginButton = (LoginButton) view.findViewById(R.id.loginfacebook);
        loginButton.setReadPermissions("email");
        // If using in a fragment
        loginButton.setFragment(this);
        // Other app specific specialization

        // Callback registration
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
                dlg.setMessage("deu"+loginResult.getAccessToken().getUserId());
                dlg.setNeutralButton("ok",null);
                dlg.show();



            }

            @Override
            public void onCancel() {
                AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
                dlg.setMessage("cancelou");
                dlg.setNeutralButton("ok",null);
                dlg.show();
            }

            @Override
            public void onError(FacebookException exception) {
                AlertDialog.Builder dlg = new AlertDialog.Builder(getContext());
                dlg.setMessage("deu erro");
                dlg.setNeutralButton("ok",null);
                dlg.show();

            }
        });


        accessTokenTracker = new AccessTokenTracker() {
            @Override
            protected void onCurrentAccessTokenChanged(
                    AccessToken oldAccessToken,
                    AccessToken currentAccessToken) {
                // Set the access token using
                // currentAccessToken when it's loaded or set.
            }
        };
        // If the access token is available already assign it.
        accessToken = AccessToken.getCurrentAccessToken();




        return view;

    }
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }



}
    
asked by anonymous 22.08.2016 / 03:19

0 answers