Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom facebook login button in android studio

In my android app, I've integrated facebook login which is working fine. Later, I've customized the login button which is also working without any problem. When the user clicks on facebook login button, it successfully let the user logged in without any problem. But the problem is, when user logged in, instead of going to next activity it displays the same login page with facebook button with logout text on facebook login button and then goes to next activity. See the image below: enter image description here

This is customized facebook login button which is working fine.See the image below after log in: enter image description here

It displays Logout text on button and then it goes to next activity. I want to go directly to next activity instead of displaying this login button with Logout text. How do I do this.? Any help..!!
Here is my code below:

xml code :

<com.facebook.login.widget.LoginButton
        xmlns:fb="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fb:login_text=""
        android:layout_gravity="center"/>

MainActivity.java

loginButton = (LoginButton)findViewById(R.id.login_button);
        loginButton.setBackgroundResource(R.drawable.fb);
        loginButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        loginButton.setCompoundDrawablePadding(0);
        loginButton.setPadding(0, 0, 0, 0);
        loginButton.setText("");
        loginButton.setReadPermissions(permissionNeeds);

loginButton.registerCallback(callbackManager,new FacebookCallback<LoginResult>()
        {
            @Override
            public void onSuccess(LoginResult loginResult)
            {
                GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback()
                    {
                        @Override
                        public void onCompleted(JSONObject user, GraphResponse response)
                        {
                            if(user !=null)
                            {
                                String firstName = user.optString("first_name");
                                String lastName = user.optString("last_name");
                                String email = user.optString("email");

                                Intent i1 = new Intent(getApplicationContext(),FacebookData.class);
                                i1.putExtra("first",firstName);
                                i1.putExtra("last",lastName);
                                i1.putExtra("email",email);
                                startActivity(i1);
                            }
                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,first_name,last_name,email");
                    request.setParameters(parameters);
                    request.executeAsync();
                }
like image 366
Ruchir Avatar asked Jun 29 '15 06:06

Ruchir


1 Answers

Set fb:logout_text="" it will solve your problem.

<com.facebook.login.widget.LoginButton
        xmlns:fb="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fb:login_text=""
        fb:logout_text=""
        android:layout_gravity="center"/>
like image 55
Ahmad Nawaz Avatar answered Sep 27 '22 23:09

Ahmad Nawaz