Follow this QuickStart for Facebook Login for Android
https://developers.facebook.com/docs/facebook-login/android
Link the Facebook SDK
mavenCentral()
compile 'com.facebook.android:facebook-login:[4,5)'
Edit Your Manifest
Open your /app/src/main/res/values/strings.xml file
<string name="facebook_app_id">id</string> <string name="fb_login_protocol_scheme">protocol</string>
Open the /app/manifest/AndroidManifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Add the following meta-data element, an activity for Facebook, and an activity and intent filter for Chrome Custom Tabs after the application element. Replace @string/appname with the name of your Facebook App:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> <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>
Provide the Development and Release Key Hashes for Your App
Download OpenSSL which is Requisite
https://slproweb.com/products/Win32OpenSSL.html
Add OpenSSL to path, so you can access it from command line
Go to JDK bin folder
cd C:\Program Files\Java\jdk1.8.0_151\bin
Add debug key hash
keytool -exportcert -alias androiddebugkey -keystore C:\Users\Mahmood\.android\debug.keystore | openssl sha1 -binary | openssl base64
Add release key hash
keytool -exportcert -alias lastlab -keystore C:\Projects\lastlab\keys\store.jks | openssl sha1 -binary | openssl base64
Read QuickStart to Add Facebook Custom Login Button
buttonSignupFacebook = findViewById(R.id.buttonSignupFacebook); facebookLoginManager = LoginManager.getInstance(); facebookCallbackManager = CallbackManager.Factory.create(); facebookLoginManager.registerCallback(facebookCallbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Toast.makeText(SelectSignupActivity.this, loginResult.getAccessToken().toString(), Toast.LENGTH_LONG).show(); } @Override public void onCancel() { } @Override public void onError(FacebookException error) { Toast.makeText(SelectSignupActivity.this, error.getMessage(), Toast.LENGTH_LONG).show(); error.printStackTrace(); } }); buttonSignupFacebook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { facebookLoginManager.logInWithReadPermissions(SelectSignupActivity.this, Arrays.asList("email", "public_profile", "user_birthday")); } });
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { facebookCallbackManager.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); }
References
https://developers.facebook.com
https://www.youtube.com/watch?v=SrAXmZkOpJI
https://developers.facebook.com/docs/facebook-login/android
https://stackoverflow.com/questions/16965058/where-is-debug-keystore-in-android-studio
https://developer.android.com/studio/publish/app-signing.html
https://github.com/facebook/facebook-android-sdk
https://developers.facebook.com/docs/facebook-login/permissions/
https://androidammy.blogspot.com/2015/09/facebook-login-with-custom-button.html