/** @return the Facebook AccessToken when signed-in with a non-expired token. */ private AccessToken getSignedInToken() { final AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken != null && !accessToken.isExpired()) { Log.d(LOG_TAG, "Facebook Access Token is OK"); return accessToken; } Log.d(LOG_TAG, "Facebook Access Token is null or expired."); return null; }
protected void checkFacebookSession() { AccessToken accessToken = AccessToken.getCurrentAccessToken(); if (accessToken != null && !accessToken.isExpired()) { GraphRequest request = GraphRequest.newMeRequest( accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject userJson, GraphResponse graphResponse) { User.facebookUser(userJson); } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,link,gender,birthday,email"); request.setParameters(parameters); request.executeAsync(); } else { List<String> permissions = new ArrayList<String>(); permissions.add("public_profile"); permissions.add("email"); LoginManager.getInstance().logInWithReadPermissions(getActivity(), permissions); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // for finding key hash of dev environment // Log.i(TAG, printKeyHash(this)); pref = getSharedPreferences(Constants.SHARED_PREFERENCE, Context.MODE_PRIVATE); // initializing facebook sdk FacebookSdk.sdkInitialize(this.getApplicationContext()); // setting the layout setContentView(R.layout.activity_login); Button clickButton = (Button) findViewById(R.id.inst); final TypedValue typedValue = new TypedValue(); clickButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String mssg = "1. Login with facebook.\n" + "2. This app will work only if other users are also on the same wifi network." + "3. Select discover tab for seeing people around" + "4. Select Match tab for seeing all your matches and chat with them by tapping on matches" + "5. view your profile and preferences from action overflow" + "6. logout by clicking logout button in action overflow"; AlertDialog.Builder myAlert = new AlertDialog.Builder(LoginActivity.this); myAlert .setMessage(mssg) .setNeutralButton( "Continue..", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setTitle("!Instructions For You!") .setIcon(typedValue.resourceId) .create(); myAlert.show(); } }); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } // System.setProperty("http.keepAlive", "false"); // login button reference loginButton = (LoginButton) findViewById(R.id.login_button); // registering callback manager callbackManager = CallbackManager.Factory.create(); loginButton.registerCallback(callbackManager, loginCallback()); // setting permissions of login button loginButton.setReadPermissions( "user_photos", "user_about_me", "user_birthday", "user_location", "user_posts"); WifiManager wifi_manager = (WifiManager) this.getSystemService(this.WIFI_SERVICE); if (!wifi_manager.isWifiEnabled()) { Toast.makeText(this, "enable your wifi", Toast.LENGTH_SHORT).show(); AppServer.getInstance(this).killServer(); NSDHelper.getInstance(this).tearDown(); MessageClientHelper.getInstance(this).terminateMessageClient(); // LoginManager.getInstance().logOut(); finish(); } else { // getting current access token accessToken = AccessToken.getCurrentAccessToken(); // if (accessToken != null && accessToken.isExpired()) { LoginManager.getInstance() .logInWithReadPermissions( this, Arrays.asList( "user_photos", "user_about_me", "user_birthday", "user_location", "user_posts")); } else if (accessToken != null && !accessToken.isExpired()) { // getPermanentToken(); requestProfileInfo(); // enterMainApp(); } } }