Facebook Login Button Not Working in Android Upper 5.0

459
February 18, 2017, at 08:41 AM

I have a problem with login facebook in android. I am slightly new in android facebook sdk. In my emulator facebook login works fine but in real phone it does not work. Also I tried 7.0 it also makes problem in emulator. I could not find any same problems on web. So here is my error message.

Thanks for any help.

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/customtabs/CustomTabsIntent$Builder;
                  at com.facebook.internal.CustomTab.openCustomTab(CustomTab.java:47)
                  at com.facebook.CustomTabMainActivity.onCreate(CustomTabMainActivity.java:67)
                  at android.app.Activity.performCreate(Activity.java:6662)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)

Also My Code in Below..

*

This Code works with emulator and below 5.0 version androids. Some > people said that it can be related with chrome-custom tab. But it > works with chrome installed devices.

*

This is my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wrexsoft.canturgut.mobileclassapp">
<uses-permission android:name="android.permission.INTERNET"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme.NoActionBar">
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <activity
        android:name=".OpenScreen"
        android:label="Init Activity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SignInScreen"></activity>
    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>
</application>

This is my activity java file...

public class OpenScreen extends AppCompatActivity {

TextView headline;
Button openScreen_button_signin;
Button openScreen_button_kusignin;
private CallbackManager callbackManager;
private DatabaseReference patideDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_open_screen);
    LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
    loginButton.setReadPermissions("email");
    loginButton.setReadPermissions("public_profile");

    patideDatabase = FirebaseDatabase.getInstance().getReference();
    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getBaseContext(), "SUCCESS", Toast.LENGTH_LONG).show();

        }
        @Override
        public void onCancel() {
            Toast.makeText(getBaseContext(), "CANCEL", Toast.LENGTH_LONG).show();
        }
        @Override
        public void onError(FacebookException exception) {
            Toast.makeText(getBaseContext(), exception.toString(), Toast.LENGTH_LONG).show();
        }
    });
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            ProgressDialog progressDialog = new ProgressDialog(OpenScreen.this);
            progressDialog.setMessage("Proceed data...");
            progressDialog.show();
            String accessToken = loginResult.getAccessToken().getToken();
            Log.i("accessToken", accessToken);
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.i("LoginActivity", response.toString());
                    // Get facebook data from login
                    Bundle bFacebookData = getFacebookData(object);
                    String username = bFacebookData.get("first_name").toString();
                    String userSurname = bFacebookData.get("last_name").toString();
                    String email = bFacebookData.get("email").toString();
                    HashMap<String, String> userData = new HashMap<String, String>();
                    userData.put("Name",username+" "+userSurname );
                    userData.put("Email",email);
                    patideDatabase.push().setValue(userData);
                }
            });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id, first_name, last_name, email");
            request.setParameters(parameters);
            request.executeAsync();
            progressDialog.cancel();
        }
        @Override
        public void onCancel() {
            Toast.makeText(getBaseContext(),"Login Cancelled", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onError(FacebookException e) {
            Toast.makeText(getBaseContext(),"Problem connecting to Facebook", Toast.LENGTH_SHORT).show();
        }
    });

    headline = (TextView)findViewById(R.id.headline);
    openScreen_button_signin = (Button) findViewById(R.id.openscreen_button_signin);
    openScreen_button_kusignin = (Button) findViewById(R.id.openscreen_button_kusissignin);
    openScreen_button_signin.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SignInScreen.class);
            intent.putExtra("signinType","normal");
            startActivity(intent);
        }
    });
    openScreen_button_kusignin.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SignInScreen.class);
            intent.putExtra("signinType","kusis");
            startActivity(intent);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent    data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
private Bundle getFacebookData(JSONObject object) {
    try {
        Bundle bundle = new Bundle();
        String id = object.getString("id");

        bundle.putString("idFacebook", id);
        if (object.has("first_name"))
            bundle.putString("first_name", object.getString("first_name"));
        if (object.has("last_name"))
            bundle.putString("last_name", object.getString("last_name"));
        if (object.has("email"))
            bundle.putString("email", object.getString("email"));
        return bundle;
    } catch (JSONException e) {
        Bundle bundle = new Bundle();
        return bundle;
    }
}}

Just in case I am using FireBase...

READ ALSO
How I Can fix more than one library with package name &#39;com.google.android.gms&#39;?

How I Can fix more than one library with package name 'com.google.android.gms'?

I tired so much things about this error but I couldn't fix it

598
Async Task blocking UI thread

Async Task blocking UI thread

I dug my way through answers here and blog posts, but just don't seem to be able to find a solution

393
Playing embeded stream on mobile devices

Playing embeded stream on mobile devices

I have a website for watching tv channels live I used bootstrap 3, my website contains some tabs and inside each one there is an embed codeThe website is working well on desktop

291
alternative if else logic for android

alternative if else logic for android

I create a script that displays the results depending on the selected options

362