Callback functions are not called in Android Facebook Login -
i developing android app. in app, integrating facebook login. have done developing facebook login once before. when develop time, facebook callback functions not called. cannot check error well. have no idea wrong.
i installed facebook sdk using gradle
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
then generated key hash , set in facebook developer settings follows:
this manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tonightfootballreport.com.tfr" > <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.write_external_storage" /> <application android:name="tonightfootballreport.model.tfrapplication" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme" > <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/facebook_app_id"/> <activity android:configchanges="orientation|screensize" android:name=".mainactivity" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:configchanges="orientation|screensize" android:name=".facebookconfigactivity" android:label="facebook" android:theme="@style/apptheme.noactionbar" > <intent-filter> <action android:name="tonightfootballreport.com.tfr.facebookconfigactivity"/> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name="com.facebook.facebookactivity" android:configchanges= "keyboard|keyboardhidden|screenlayout|screensize|orientation" android:theme="@android:style/theme.translucent.notitlebar" android:label="@string/app_name" /> <provider android:authorities="com.facebook.app.facebookcontentprovider1817380365215100" android:name="com.facebook.facebookcontentprovider" android:exported="true" /> </application> </manifest>
as can see facebook login not in main activity , set facebookconfigactivity in developer settings.
then when click button in mainactivity, facebookconfigactivity opened , perform facebook login. below code.
public class facebookconfigactivity extends appcompatactivity { private callbackmanager callbackmanager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); facebooksdk.sdkinitialize(getapplicationcontext(), appconfig.facebook_request_code); appeventslogger.activateapp(this); setcontentview(r.layout.activity_facebook); setupcallback(); loginintofacebook(); } private void loginintofacebook() { loginmanager.getinstance().loginwithreadpermissions(facebookconfigactivity.this,arrays.aslist("public_profile")); } private void setupcallback() { callbackmanager = callbackmanager.factory.create(); loginmanager.getinstance().registercallback(callbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { //show share alert //then share log.i("login_success","login_success"); } @override public void oncancel() { toast.maketext(getbasecontext(), "operation canceled", toast.length_short).show(); finish(); } @override public void onerror(facebookexception error) { toast.maketext(getbasecontext(), "error in connecting facebook", toast.length_short).show(); finish(); } }); } }
as can see, simple facebook login. when click login button, enter credentials facebook login form can see below.
then after click ok in next step, facebookconfigactivity displayed , no callback function called. if click cancel, facebook cancel callback not called well. possible error?
you forgot put listener in onactivityresult()
put below code in onactivityresult method of activity:
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); callbackmanager.onactivityresult(requestcode, resultcode, data); }
Comments
Post a Comment