Hello friends, welcome to our new tutorial. In this tutorial we will create a login with facebook android app using android studio and facebook sdk 4.0. So lets begin.
Creating Android Project
- Open Android Studio and Click on File-> New ->New Project
- Give your application a name (in my case it is AndroidLogin) and a package (mine is net.simplifiedcoding)
- Select Phone or Tablet
- Select Blank Activity with Fragment.
- Leave the rest things as it is and finish.
- Now once our project is ready we need to configure a lot of things so lets begin.
Prerequisites for creating Login with Facebook Android App
- Facebook app configured and linked to our android app
- Facebook SDK
- Facebook App ID
- Android Key Hash
- Facebook Activity
Lets start with creating Facebook App
Configuring Facebook SDK to Android Studio
- Go to your gradle scripts -> build.gradle(Module:app)
- Add the following code
1 2 3 4 5 | repositories { mavenCentral() } |
- Now add a new dependency for Facebook SDK
- Inside dependencies add this line
1 2 3 | compile 'com.facebook.android:facebook-android-sdk:4.0.0' |
- It will download facebook sdk and will take some time. It can take long time if you have a slow internet connection. So mean while lets create our facebook app.
Creating Facebook App
- Go to https://developers.facebook.com/. If you have not registered yourself as a developer yet then facebook will ask you to register as a developer. Simply register as a developer. (Congrats you are now a developer :P)
- From the top navigation menu hover over my apps.
- Then click add a new app.
- You will asked to select a platform, click on android.
- On the new page you can select quick start or you can select skip and create app id from the upper right corner.
- Click on skip and create app id.
- Give a display name and a namespace for your app as shown in the image below.

- Click create app id.
- You will be redirected to your apps dashboard.

- Here you can get your app id. Copy the app id it will be used further. (I have made my app id hidden because i cant let you see it for security reasons)
- Now from the left click on settings.
- Click on add a platform and select android.
- Enter your package name and class name of your main activity and click on save changes
- The last thing you need is your App Key Hashes.

Generating Key Hashes for your Login With Facebook Android App
- Go to android studio.
- On your project open your strings.xml file (res->values->strings.xml)
- Add the below code
1 2 3 | <string name="app_id">YOUR APP ID</string> |
- Replace your actual app id with your app id.
- Now go to your AndroidManifest.xml
- First add internet permission using the following code
1 2 3 | <uses-permission android:name="android.permission.INTERNET"/> |
- Add a this meta-data code inside your application
1 2 3 | <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> |
- This is containing our app id which we defined inside strings.xml.
- Now create a new class in your package and name it MyApplication (name doesn’t matter you can name it anything)
- Copy the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | package net.simplifiedcoding.androidlogin; import android.app.Application; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; import android.util.Base64; import android.util.Log; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * Created by Belal on 5/3/2015. */ public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); printHashKey(); } public void printHashKey(){ // Add code to print out the key hash try { PackageInfo info = getPackageManager().getPackageInfo( "net.simplifiedcoding.androidlogin", PackageManager.GET_SIGNATURES); for (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) { } } } |
- Make sure in the above code your provide your application’s package name.
- The above class will print the KeyHash in the logcat. But we still need to define this class inside your AndroidManifest.
- Go to AndroidManifest.xml again and Inside application opening tag define your class as shown below
1 2 3 4 5 6 7 8 9 10 11 12 13 | <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> . . . </application> |
- Now execute your app and you will get your keyhash in your logcat.
- Copy the keyhash and enter that to your app settings in facebook and click save.
Creating your Login With Facebook Android App
- For facebook login Facebook SDK provides an activity that will open while login. You only need to add that activity to your manifest file.
- Add the facebook activity using the following code.
1 2 3 4 5 6 7 | <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" /> |
- So your final AndroidManifest.xml would be like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.simplifiedcoding.androidlogin" > <uses-permission android:name="android.permission.INTERNET"/> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> <activity android:name=".MainActivity" 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="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" /> </application> </manifest> |
- Now come to your fragment layout and create a TextView and a Facebook Login Button. The button is provided by facebook sdk. You can use the below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:orientation="vertical" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivityFragment"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView" android:layout_centerHorizontal="true"/> <com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> |
- We will show the user name in the textview after successful login.
- Go to your MainFragment.java and copy the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | package net.simplifiedcoding.androidlogin; import android.content.Intent; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.facebook.AccessToken; import com.facebook.AccessTokenTracker; import com.facebook.CallbackManager; import com.facebook.FacebookCallback; import com.facebook.FacebookException; import com.facebook.FacebookSdk; import com.facebook.Profile; import com.facebook.ProfileTracker; import com.facebook.login.LoginResult; import com.facebook.login.widget.LoginButton; /** * A placeholder fragment containing a simple view. */ public class MainFragment extends Fragment { private CallbackManager callbackManager; private TextView textView; private AccessTokenTracker accessTokenTracker; private ProfileTracker profileTracker; private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { AccessToken accessToken = loginResult.getAccessToken(); Profile profile = Profile.getCurrentProfile(); displayMessage(profile); } @Override public void onCancel() { } @Override public void onError(FacebookException e) { } }; public MainFragment() { } @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); callbackManager = CallbackManager.Factory.create(); accessTokenTracker= new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { } }; profileTracker = new ProfileTracker() { @Override protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { displayMessage(newProfile); } }; accessTokenTracker.startTracking(); profileTracker.startTracking(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_main, container, false); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); textView = (TextView) view.findViewById(R.id.textView); loginButton.setReadPermissions("user_friends"); loginButton.setFragment(this); loginButton.registerCallback(callbackManager, callback); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } private void displayMessage(Profile profile){ if(profile != null){ textView.setText(profile.getName()); } } @Override public void onStop() { super.onStop(); accessTokenTracker.stopTracking(); profileTracker.stopTracking(); } @Override public void onResume() { super.onResume(); Profile profile = Profile.getCurrentProfile(); displayMessage(profile); } } |
- Run your app now and Bravo it works 😉
- If you are having troubles then you can download the source code of this project from here
Some more android tutorials you should check
So thats all for this login with facebook android app tutorial friends. Feel free to ask if you have any queries or troubles following the steps. Thank you 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
When i create a Blank Activity with Fragment it creates me an activity that extends from ActionBarActivity and then creates a class that extends from Fragment, how can i execute my MainFragment from an class that extends form ActionBarActivity.
I am not getting what you want to ask? Tell me your actual requirement.. or you can check details about fragments from here – > http://developer.android.com/training/basics/fragments/creating.html
hey bilal khan …can you make an tutorial on sharing photos videos or status from android app to facebook automatically…
from your activity you can go to mainfragment, after setcontentview paste this
if (savedInstanceState == null){
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new MainFragment ()).commit();}
Your tutorial is great and helped me a lot but I want to create the login button on a popup window, how should I do that? and how can I hide the login button when the user has already loged in? and will you do some tutorials on facebook sharing and like button too?
Ok stay tuned I will try to help you with some more tutorials ASAP 🙂
Is there a way to use the FB SDK log in button without using a fragment? Can I just put it straight on the MainActivity? If so, how do I do this?
Yeah you can obviously do that
How can i integrate this code in my main activity without creating a fragment class??
//refer the link
http://www.androidwarriors.com/2016/02/facebook-integration-in-android-studio.html
Please tel me the way to do this without creating main fragment…..
I downloaded the code, but it is a game. Please, could you check the link?
Sorry for the inconvenience I corrected the link you can check it now… 🙂
Hai, i have a problem, when i connect in my account its work, but in the second part it say the my hash key is not stored, what does it mean, i use your applciation. Thanks for your help
Thanks man! I got your site after one week and you wont believe even after trying millions of options it dint work. Amazing work 😀
You welcome bro 🙂
I try this code butt my application not open just an error message shown “Your application is forcefully stoped”
In my case it is working absolutely fine as you can see on the video. Send me your code.. I will check it
mine also same problem 🙁
Check what exception your app is throwing from your logcat
hi bro, i have the same problem, can you help me???
can i send you my code to you see it?
if you say yes, where and how i can send you this??
I need to get the email id, phone number , password of the after login. please suggest how to get that. Thanks i advance.
List permissions = new ArrayList ();
permissions.add(“email”);
Add all the permissions you need and then
loginButton.setReadPermissions(permissions);
For more information you can check the sdk docs from here https://developers.facebook.com/docs/facebook-login/android/permissions
Thanks a lot! work 100%.. How I can start another activity after login ? And how can I pass the parameters of facebook to the new activity?
how can I start new activity after successful login?
You can use Intent to start another activity..
How?
Hi, great tutorial but i seem to have an error through your code. when i run inspect code in android studio it comes up with an error such as…
Location
class anonymous in FacebookCallback callback (mobliedevelopment.terrelsimeongordon.hwl_fb.MainFragment)
Problem synopsis
Variable ‘accessToken’ at line 38 is never used
i downloaded the source code yet the same error comes up
this is the code that android is complaining about?
private FacebookCallback callback = new FacebookCallback() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
displayMessage(profile);
}
do you have any clue why it is not working and why it can not find accessToken? grateful if you could help answer this 1 million dollar question 🙂
Hi sorry about that i just found the issue 🙂
just wondering if its possible to extend just an activity instead of an ActionBarActivity for the MainActivity? if so how would you i go about altering this code to that requirement?
How do i change the height and width of the Login button ( com.facebook.login.widget.LoginButton ) i m using the 4.1 sdk for facebook
you can also create your own button 🙂
thanks bro.
its really useful article.
I need to get email Id of the user, added the permission of it too but How do i print that in the TextView. Profile.getEmailID(); doesn’t work. Please help
did you find any solution ?
i m not getting the friend list
i need the friend list of my friends but i m not.
plz tell me the permissions to write for it how can we aceess all that ..
i am new in android
The problem is how to call another activity right after authorization succeed and remove logout button.
thanks in advance……
help me to print complete profile information of the user.
Thank you
Session and graph is not working in this sdk version. so please give the code to get the complete profile information.
your tutorial heiped me to get the username from profile using profile.getName();
similarly i need to get the all profile information. please give the code.
Thanks in advance
ok stay tuned and I will try to post a new tutorial for this
login page of facebook appeared only once during the first run. Subsequent running doesnt show it.Please help me.
also during debugging, variable profile gets null value. iam a beginner to android. please help
Thanks
getting error in logcat please sir help me
Error:A problem occurred configuring project ‘:app’.
> Could not download facebook-android-sdk.aar (com.facebook.android:facebook-android-sdk:4.0.0)
> Could not get resource ‘https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/4.0.0/facebook-android-sdk-4.0.0.aar’.
> Could not GET ‘https://jcenter.bintray.com/com/facebook/android/facebook-android-sdk/4.0.0/facebook-android-sdk-4.0.0.aar’.
> d29vzk4ow07wi7.cloudfront.net
Hi,
I am able to integrate facebook login into my app successfully by follwing your post. The actual req of my app is to trigger facebook status at the end of every month. When i try to login after two months login dialog does not open up. It throws a FacebookAuthorizationException. Can you please help me in figuring it out.
Note: I believe due to access token expiry facebook login dialog does not open. You can check it
Thanks.
After clicking the Facebook login button, I am getting an error saying you are not logged in. please log in and try again…how to login?
10-16 15:59:05.620 1304-1335/? E/InputDispatcher﹕ channel ‘c10b4fa com.example.dipali.androidlogin/com.example.dipali.androidlogin.MainActivity (server)’ ~ Channel is unrecoverably broken and will be disposed!
I have this error.How can i solve this error?
Try downloading my source code and check you are still getting the error or not?
I referred your source code Still i am having this error.Process
Couldn’t load memtrack module (No such file or directory)
10-17 11:11:42.089 2347-2347/? E/android.os.Debug﹕ failed to load memtrack module: -2
10-17 11:11:49.677 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
10-17 11:11:49.677 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
10-17 11:11:50.245 2384-2384/? E/memtrack﹕ Couldn’t load memtrack module (No such file or directory)
10-17 11:11:50.246 2384-2384/? E/android.os.Debug﹕ failed to load memtrack module: -2
10-17 11:11:50.345 2384-2392/? E/art﹕ Thread attaching while runtime is shutting down: Binder_1
10-17 11:11:53.054 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
10-17 11:11:53.055 1837-1837/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn’t include a PendingIntent in the extras?
10-17 11:11:59.472 2393-2393/? E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
10-17 11:11:59.956 2393-2393/? E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-17 11:11:59.956 2393-2393/? E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
10-17 11:11:59.956 2393-2393/? E/chromium﹕ [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
10-17 11:12:00.266 2393-2393/? E/DataReductionProxySettingListener﹕ No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
10-17 11:12:00.913 953-953/? E/SELinux﹕ avc: denied { find } for service=batteryproperties scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:healthd_service:s0 tclass=service_manager
10-17 11:12:04.515 2393-2474/? A/chromium﹕ [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
——— beginning of crash
10-17 11:12:04.515 2393-2474/? A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 2474 (GpuThread)
10-17 11:12:04.634 962-962/? A/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-17 11:12:04.634 962-962/? A/DEBUG﹕ Build fingerprint: ‘generic_x86/sdk_google_phone_x86/generic_x86:6.0/MRA44C/2166767:eng/test-keys’
10-17 11:12:04.634 962-962/? A/DEBUG﹕ Revision: ‘0’
10-17 11:12:04.634 962-962/? A/DEBUG﹕ ABI: ‘x86’
10-17 11:12:04.634 962-962/? A/DEBUG﹕ pid: 2393, tid: 2474, name: GpuThread >>> com.example.dipali.androidlogin <<>> com.example.dipali.androidlogin <<<
10-17 11:15:52.846 962-962/? A/DEBUG﹕ signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr ——–
10-17 11:15:52.851 962-962/? A/DEBUG﹕ Abort message: '[FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
'
10-17 11:15:52.851 962-962/? A/DEBUG﹕ eax 00000000 ebx 000009b2 ecx 00000a05 edx 00000006
10-17 11:15:52.851 962-962/? A/DEBUG﹕ esi a04bf980 edi 00000000
10-17 11:15:52.851 962-962/? A/DEBUG﹕ xcs 00000073 xds 0000007b xes 0000007b xfs 000000c7 xss 0000007b
10-17 11:15:52.852 962-962/? A/DEBUG﹕ eip b73b55d6 ebp 00000a05 esp a04bec40 flags 00200206
10-17 11:15:52.852 962-962/? A/DEBUG﹕ backtrace:
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #00 pc 000845d6 /system/lib/libc.so (tgkill+22)
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #01 pc 00081618 /system/lib/libc.so (pthread_kill+70)
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #02 pc 00027205 /system/lib/libc.so (raise+36)
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #03 pc 000209e4 /system/lib/libc.so (abort+80)
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #04 pc 0037328a /system/app/webview/webview.apk
10-17 11:15:52.852 962-962/? A/DEBUG﹕ #05 pc 000009a3 /data/misc/shared_relro/libwebviewchromium32.relro
10-17 11:15:53.423 962-962/? A/DEBUG﹕ Tombstone written to: /data/tombstones/tombstone_03
10-17 11:15:53.423 962-962/? E/DEBUG﹕ AM write failed: Broken pipe
10-17 11:15:56.910 954-954/? E/libEGL﹕ called unimplemented OpenGL ES API
10-17 11:15:56.911 954-954/? E/SurfaceFlinger﹕ glCheckFramebufferStatusOES error -2129925904
10-17 11:15:56.911 954-954/? E/SurfaceFlinger﹕ got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
Hi, that was an really awesome tutorial, I run the app, go the output. But I tried to reopen means its shows the HashKey error. Please guide me
Check you have generated the HashKey correctly or not?
How can i dentify the keyhash on the logcat ? :/
follow the post carefully.. and after writing the keyhash part run you app and check the logcat for keyhash
Hi Belal u have done a good job. I tried many totorials but got disappointed. i used your tutorial in my case it is working, but if i try to login second time it shows the message “This app has no Android key hashes configured. pls configure hash key. but i configured key hash succesfully still get error msg from second time login.. pls help me..
I am making one movie review app, and I tried to create a login with facebook button at my login page.
When I start my app for 1st time, then it works fine, get logged in from Facebook, and also able to display name.
But after the 1st time when I log out from it, and try to log in again, then it always shows ” The app has no Android key hashes configured. Configure your app key hashes at …………”
Please guide me and help me with solution to it. Please as I have to submit it as a project day after tomorrow. please
i have issue when i created facebook app id then :
There was a problem verifying the package name com.example.vicky.facelogin on Google Play. Please check the package name and try again.
If your app isn’t listed publicly on Google Play yet you can ignore this message
please help me
You can ignore this message.. or you can try creating a new project with different package name
Hi belal, awesome tut! 🙂
i am not getting my KEY HASH on log cat 🙁 and tried it by using openSsl also bt it is also not working.. can you please help me.. 🙁
Hi Belal,
I have tried your code and it’s working as i want but i have one question that now i want to save user data who login with facebook at mysql database. I have POST Json API but not getting anything after spending hours on google. Can anyone help me ?
same problem with me please help anyone.
Great Tutorial !!!!!, Thanks
Hi Bilal,
Thank you for this great tutorial. I just want to share one solution for those who’s getting error of hash key. When you run your programme at first time it’s successfully login but second time it give error of hash key. The solution is the key which is shown in device as a error is your correct hash key so save this key on facebook app setting and the error is gone. thanks
Bro..It’s getting Unfortunately Error,
yes me too and when corrected it says hello world only
Hi thanks for this tutorial. I successfully created and executed the app.
But i want to get facebook friends list. I saw the documentation and it was little bit confusing. How to proceed , please help. Thanks in advance.
Hello there, i have seen this tutorial and it is very useful to me, but i have one question. How can i create a login activity with facebook in it? Means that there is simple login button and i don’t want to use fragment for it. So how to do this, can you explain or give me some idea to do it. Thanks for help!!!
I got a FacebookException i.e. couldn’t connect to the server, after click on login button and comes progress bar.
please reply, thanks in advance.
how to get the phone number from facebook
I tried your code, but it appear only with mainactivity saying hello world, there is no button. I checked code and found other class is not related with mainactivity. Please check the Link given below for complete code
https://www.dropbox.com/sh/x68jby50q8rq6kh/AACRIDh3h2VCrNlLoRkBWsPVa?dl=0
I got the answer just Implement a fragment in main activity and call main fragment thankyou
Hai
After login i want to fetch the user email id and mobile number.
if u have any materials please share me.
Thank you.
Log in attempt failed: LoginActivity could not be started
at com.facebook.login.LoginManager.startLogin(LoginManager.java:382)
i have run app then above error show
if (!started) {
FacebookException exception = new FacebookException(
“Log in attempt failed: LoginActivity could not be started”);
logCompleteLogin(LoginClient.Result.Code.ERROR, null, exception);
this.pendingLoginRequest = null;
throw exception;
}
this is line no 382 place say how can start the LoginActivity??
Appreciate your work but i need user email address and phone number How can i get this ?
hey belal,
I want to save user data ( user name and email id) to my data base, how to make it. and thanks for grt tuts.
How i create icon to Option menu string
hi man!… I emerged a mistake is that when runing the app does not open the LAYOUT where is the option to sign, that is only the MAIN ACTIVITY where i get nothing. I hope you can help me
how cam ve get the emailid after login or whow can we fetch the email id in facebook
How to call a fregment from activity
hi i copied the code but iam not getting image when iam logged in.. Can you give me the code for that how to get the user image when logged into app..
what about the main activity
?
How can we use this code without using MainFragment?….reply fast
Cant find Hash Key ..Please helpppp
Hey aakriti….just change your logcat from verbose to debug…
and then in search area wite key hash….you will get it (hash key) in logcat…
Hope this will help u or anybody else 🙂
ERROR: FAILED TO RESOLVE:com.facebook.android:facebook-android-sdk:4.0.0′
how to get user email addreess from facebook login??
Hi, first thanks for the tutorial, its easy to follow and implement..
i have a question…
After successful login, how and where can i use intent to go other activity..
For now, after login also coming back to LoginActivity. Can you please clear the doubt?
@Override
public void onSuccess(LoginResult loginResult) {
// Facebook Email address
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.v(“LoginActivity Response “, response.toString());
try {
Toast.makeText(getApplicationContext(), “Name ” + object.getString(“name”)
+”\nEmail “+object.getString(“email”), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString(“fields”, “id,name,email,gender, birthday”);
request.setParameters(parameters);
request.executeAsync();
}
hi
I want to use in my app login activity instead of fragment
APK build is successful but am gointing java.lang.NullPointerException: Attempt to invoke virtual method ‘int java.lang.Object.hashCode()’ on a null object reference error occur in catalog ..
I am a php developer, Now I want to develop android app. Get some suggesion & tutorial link from which I learn very fast. Please help
first be familiar with core java then start to learn android from youtube or tutorials pointand many other.
How to get all albums from facebook in nadroid programatically???
please help me,,,
how to get all album’s photos in android apps???
hey where is main activity ?????
@tom- main activity is automatically generated when you choose blank activity with fragment….you dont need to do any modifications to it for this code.
Hope it helped you 🙂
i didn’t get output in mobile..when i click on login with Facebook it is loading and stopped, not shown login page in mobile.
same happened with me also it loading loading loading and then stopped pls help
i want save user id and passward how to do plzzzzz help me out bro
Hi Sir, The app is not working for me i am not able to understand where to put code should i make
1.fragment (Blank Fragment)
2.MainActivity
3.activity_main.xml
4.fragment.xml
what to put in MainActivity ??????
Please answer
Thank you
Yes you need to create a layout call it Fragment and add the code there for KeyHash
i m getting a blank white screen . I Followed all the steps listed above.
help me
same here, just a white screen but there’s no any syntax error
where is the layout for fragment_main?
sir, how we create own button?
find an error in mainactivity in setContentView() method
all working is fine but this code not run on android lollipop version…. why this is happened?…
Hi I’m just learning android and found it interesting to perform the user login but I can not do this supplement shows me red line last one:
It happens that I have MainActivityFragment and really in the tutorial nowhere shown or MainActivityFragment is added and the truth is that I can put donot to make it work.
Thank you.
Hello, i have implemented the code below and its work but i have a probleme when i try to log with another facebook account.
Please have you an idea to solve the problem ?
Thank’s
Reda
at the first time of login, i am getting profile null, what should i do?
Can you do also the tutorial how to put the facebook detail like username , email to database mysql for android app? Thank You
how to do it with custom button. Not using facebook inbuilt button.
the login works for only developer, i.e., my id. why not for other.
when others login from it, an error appears that app is in development mode