java - Android Application Login with Facebook is not working with Facebook App installed -


this code working when uninstalled facebook app didn't work facebook app installed. i'm using facebook sdk 4.0.

this code

package com.example.nhp04.gqfood; 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.profile; import com.facebook.login.loginresult; import com.facebook.login.widget.loginbutton;    public class login extends appcompatactivity implements animation.animationlistener {  private string info = ""; private loginbutton loginbutton; private callbackmanager callbackmanager; private accesstokentracker tracker;      protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         facebooksdk.sdkinitialize(getapplicationcontext());         callbackmanager = callbackmanager.factory.create();         setcontentview(r.layout.activity_login); loginbutton = (loginbutton)findviewbyid(r.id.login_button);    loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() {         @override         public void onsuccess(loginresult loginresult) {             accesstoken accesstoken = loginresult.getaccesstoken();             profile profile = profile.getcurrentprofile();             info = ("user id: " +       loginresult.getaccesstoken().getuserid() + "\n" + "auth token: " + loginresult.getaccesstoken().gettoken());                 }                  @override                 public void oncancel() {                     info = ("login attempt canceled.");                 }                  @override                 public void onerror(facebookexception e) {                     info = ("login attempt failed.");                 }             });             system.out.println(info);             tracker = new accesstokentracker() {             @override             protected void oncurrentaccesstokenchanged(accesstoken oldaccesstoken, accesstoken currentaccesstoken) {              }         };         tracker.starttracking();     }     } 

this function checking login

public boolean isloggedin() {     accesstoken accesstoken = accesstoken.getcurrentaccesstoken();     return accesstoken != null; } 

this on resume , on stop methods

@override protected void onresume() {     super.onresume();     if (isloggedin()){         intent home = new intent(this, home.class);         startactivity(home);     } }  @override protected void onstop() {     super.onstop();     tracker.stoptracking();     finish(); } 

and onactivityresult

@override protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     callbackmanager.onactivityresult(requestcode, resultcode, data);     if (resultcode == result_ok) {         intent home = new intent(this, home.class);         startactivity(home);     } else {         toast.maketext(getapplicationcontext(), "unable login please check internet connection",toast.length_long).show();     } } 

where onactivityresult() code. in onactivityresult() need use callbackmanager. user below code:

 @override public void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     callbackmanager.onactivityresult(requestcode, resultcode, data);  } 

above work both in fragment/activity. make sure have

1. facebook app installed on testing device 2. in facebook developer account check whether have mentioned  - correct package name : refer android project manifestfile.xml  - check have mentioned correct launcher class - check have given correct debug/release hash key  3. cross check facebook application id , mentioned in manifestfile.xml facebook meta data same 

in code change below

create callbackmanager after setcontentview(...);

change below facebooksdk.sdkinitialize(getapplicationcontext()); appeventslogger.activateapp(this); setcontentview(r.layout.activity_login); callbackmanager = callbackmanager.factory.create();

remember if facebook issue problem lies within dont waste time in searching other thing. put log in failure method in callback of facebook sdk.

post comment if still have problem


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -