Android facebook sdk 3.0 login by custom button

梦想与她 提交于 2019-12-21 23:05:46

问题


Android facebook sdk 3.0 login by custom button. I dont want to use fragment . Just click a button then facebook login fetch the user name ,email,uid and the access token.

If facebook login in a dialog box there is no problem.


回答1:


1- add facebook login activity in your AndroidManifest.xml

 <activity android:name="com.facebook.LoginActivity" android:screenOrientation="portrait"></activity>

2- on button click

Intent  i = new Intent(this,com.facebook.LoginActivity.class);
startActivity(i);

This will open facebook login activity.

I recommend you this material about facebook Session: https://developers.facebook.com/docs/reference/android/3.0/Session/

Session can be managed by UiLifecycleHelper




回答2:


I realize this is an old thread but I was having a similar issue and the other answer did not work for me. I wanted to have my own custom button have the same functionality as the built in Login Button.

The first step was to include the built in facebook button in my xml file but set its visibility to "gone" so it cannot be seen by the user.

<com.facebook.widget.LoginButton
        android:id="@+id/authButton"
        android:visibility="gone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        />

In my main activity, I then defined the hidden facebook button and the button I wanted to use

fbLoginButton = (Button) findViewById(R.id.authButton); //built in facebook button
customButton = (Button) findViewById(R.id.customButton); //my custom button

Then in an onClickListener for the custom button, I used the ".performClick" method on the facebook button

customButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        fbLoginButton.performClick();
    }
});

This works like a charm for me. Hopefully this can help somebody.



来源:https://stackoverflow.com/questions/15509848/android-facebook-sdk-3-0-login-by-custom-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!