Android Studio Facebook Login Share Like Tutorial – Part 2

Tan Woon How

He is a learner and know little around .Net and Java. He learned and share if you see his mistake... feel free to comment and laugh at him... and also please help to correct him.

You may also like...

  • swtu j

    Very nice tutorial ….
    its working for me …
    Thanks 🙂

  • Ali Steele

    Hi,
    I have the code working on the first try, but once the user has accepted the permissions on facebook, logs out and then tries to log in the app crashes. Saying the key has does not match. Any suggestions?

  • Elisa Leehan

    Hi there, I used your code which was really helpful but when running on my phone or emulator, it won’t connect after hitting the log in to facebook button. Do I need to have facebook downloaded on the phone/emulator?

    • Elisa Leehan

      I finally tried it while connected to wifi and it when prompting the login button a screen appears saying I am not logged in and to try again. I am logged in online in chrome, so I am confused why it isn’t working.

      • Tan Woon How

        Yes. You need to login. Its doesn’t matter whether your device or emulator got fb apps or not. If fb apps doesn’t exists it will use the web version to ask you to grant permission.

        • Elisa Leehan

          ok thanks but it never gives me a chance to login. It just says I am not logged in

          • Tan Woon How

            Did you see any error in logcat panel ?

          • Elisa Leehan

            Nope

  • Yash Piplani

    Hey, in “activity_main.xml” file, you have written inside Image Views ‘android:src=”@drawable/people” ‘….but you didn’t mention about drawable folder..what is in it??

    • Tan Woon How

      Ah sorry, i think i missed that. I actually get it from …sorry i forgot where i got it. will find back the link. But you could get it from the project.. Update later.

      • Yash Piplani

        No problem..I think I don’t need those images..I just wanted to understand the code for login through facebook..found it very useful..Thanks a ton mate!

        • Tan Woon How

          ya. i’m about to give up on finding the link and tell you that’s not important 😛 .. I just format my laptop not know where i get it from.. hahaa…will try search again with google image….cheers..

          • Yash Piplani

            Could you please tell me that when are we calling the MainActivity and from are we calling it??

          • Tan Woon How

            Call it from LoginActivity.java if the user not logged in before lines 73-74.

            Or they have logged in and this piece of information is stored in shared preference, and you could refer to lines 46-47

            Beside that i found the link for the images and update the article. Thanks for reporting this.

          • Yash Piplani

            I followed the instructions completely and when I am running the app on emulator,it is crashing before displaying the LoginActivity..why is it happening??

          • Tan Woon How

            Could you paste the error message from the logcat panel?

          • Yash Piplani

            Is it because we have not provided the image to the “login with facebook” button?
            Do we need to provide an image to it?

          • Tan Woon How

            Check you LoginActivity.xml, you should have this

          • Yash Piplani

            Yes, but in the first line it is ” ” instead of ” “..both ‘L’ and ‘B’ are in capitals.

          • Tan Woon How

            So now working? You try to sync the Gradle it should be work.

          • Yash Piplani

            I am just writing the code for Key Hash initially but it is still stopping when I am launching it on the emulator.These are the error messages in the logcat panel-
            FATAL EXCEPTION: AsyncTask #1

            Process: in.breadloaf.loginfb, PID: 1672

            java.lang.NullPointerException

            at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:911)

            at com.facebook.internal.Utility.queryAppSettings(Utility.java:846)

            at com.facebook.login.widget.LoginButton$1.run(LoginButton.java:491)

            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

            at java.lang.Thread.run(Thread.java:841)

          • Tan Woon How

            Not sure what is the error. Have you set your FB id? If you ok, you could send it to my email admin[a]instinctcoder[dot]ccom, let me have a look.

          • Yash Piplani

            It’s working now..thanks a lot buddy!!

          • Tan Woon How

            OK, Great!! Do you mind to share what you done in order to get rid of the issue? Your step may benefit others. Thanks first.

          • Yash Piplani

            I just followed all the steps mentioned in this article..guys all the steps given here are simple and perfect..just don’t copy and paste all the code,use this article as a reference. Thank You.

          • Yash Piplani

            I just followed the steps mentioned in the article,these steps are very simple and perfect. Guys just don’t copy and paste all the code, use this article as a reference. Great work Tan Woon.
            Thank You.

          • Yash Piplani

            And the project you have provided is giving different result from the one you showed in the video.It is showing the following window:

          • Tan Woon How

            ??What do you mean? I Cant see the picture,

          • Tan Woon How

            This is because you did not have valid hashkey. Thid happened to me before somehow the hashkey generated by ssl is not valid. Please get it from the showHashKey in LoginActivity