java - LoginButton Facebook with appcompat-v7:22.1.1 -
has try using appcompat-v7:22.1.1 facebook login sdk version 4.0.0 tried failed,and dont know how fix it, when try using different layout works, when using layout contain loginbutton facebook not work, here code :
my activity looks :
import android.content.intent; import android.content.pm.packageinfo; import android.content.pm.packagemanager; import android.content.pm.signature; import android.os.bundle; import android.os.persistablebundle; import android.support.v7.app.appcompatactivity; import android.util.base64; import android.util.log; import android.view.menu; import android.view.menuitem; import com.facebook.accesstoken; import com.facebook.callbackmanager; import com.facebook.facebookcallback; import com.facebook.facebookexception; import com.facebook.facebooksdk; import com.facebook.graphrequest; import com.facebook.graphresponse; import com.facebook.appevents.appeventslogger; import com.facebook.login.loginresult; import com.facebook.login.widget.loginbutton; import org.json.jsonexception; import org.json.jsonobject; import java.security.messagedigest; import java.security.nosuchalgorithmexception; import java.util.arrays; import java.util.list; import santana.gujarat.chatmeet.r; /** * created root on 14/05/15. */ public class loginactivity extends appcompatactivity implements graphrequest.graphjsonobjectcallback { private static final list<string> permissionneeds= arrays.aslist("user_photos", "friends_photos", "email", "user_birthday", "user_friends"); private loginbutton loginbutton; private callbackmanager callbackmanager; private graphrequest request; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.layout_login_activity); try { packageinfo info = getpackagemanager().getpackageinfo( "com.facebook.samples.loginhowto", packagemanager.get_signatures); (signature signature : info.signatures) { messagedigest md = messagedigest.getinstance("sha"); md.update(signature.tobytearray()); log.d("keyhash:", base64.encodetostring(md.digest(), base64.default)); } } catch (packagemanager.namenotfoundexception e) { } catch (nosuchalgorithmexception e) { } loginbutton = (loginbutton) findviewbyid(r.id.login_button); loginbutton.setreadpermissions(permissionneeds); facebooksdk.sdkinitialize(getapplicationcontext()); callbackmanager = callbackmanager.factory.create(); loginbutton.registercallback(callbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { loginresult.getaccesstoken(); request = graphrequest.newmerequest(loginresult.getaccesstoken(), loginactivity.this); request.executeasync(); log.d("fb granted", loginresult.getrecentlygrantedpermissions().tostring()); log.d("fb denied", loginresult.getrecentlydeniedpermissions().tostring()); accesstoken.getcurrentaccesstoken(); } @override public void oncancel() { } @override public void onerror(facebookexception e) { log.d("error login",e.getmessage()); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); callbackmanager.onactivityresult(requestcode, resultcode, data); } @override protected void onresume() { super.onresume(); // logs 'install' , 'app activate' app events. appeventslogger.activateapp(this); } @override public void oncompleted(jsonobject user, graphresponse response) { log.d("resultfb", user.tostring()); try { log.d("resultfb",user.getstring("username")); } catch (jsonexception e) { } } }
my manifest :
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.read_external_storage"/> <application android:name=".appcontroller" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/theme.appcompat" > <activity android:name=".activity.registeractivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".activity.loginactivity" /> <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" /> <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/facebook_app_id" /> </application> </manifest>
my layout :
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <com.facebook.login.widget.loginbutton android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_centervertical="true" android:layout_centerhorizontal="true" /> </relativelayout>
and logcat error :
java.lang.exceptionininitializererror @ java.lang.reflect.constructor.constructnative(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:417) @ android.view.layoutinflater.createview(layoutinflater.java:587) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:687) @ android.view.layoutinflater.rinflate(layoutinflater.java:746) @ android.view.layoutinflater.inflate(layoutinflater.java:489) @ android.view.layoutinflater.inflate(layoutinflater.java:396) @ android.view.layoutinflater.inflate(layoutinflater.java:352) @ android.support.v7.app.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:249) .. caused by: null at android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:106) at santana.gujarat.chatmeet.activity.listpeopleactivity.oncreate(listpeopleactivity.java:18) ...
Comments
Post a Comment