I''m following this Tutorial but so far I can't make it work, though this is from a year ago or so...
I'm using androidStudo 1.2.2 and FacebookSDK 4.
I want a simple login into facebook using a custom button, like the one shown in this image:
Now, in the example from the tutorial I'm having problems with the Session
variable, it says it cannot resolve it, neither getActivity()
Has naybody tried this on FacebookSDK4.0?
Is that a correct approach or maybe there is something more updated?
Thanks in advance!
Step 1: First add FrameLayout and make facebook button visibility="gone" and add your custom button. Don't forgot to put
xmlns:facebook="http://schemas.android.com/apk/res-auto"
in your main layout.Step 2: Initialize
FacebookSdk
inonCreate
before inflecting layout.FacebookSdk.sdkInitialize(this.getApplicationContext());
Step 3: add this into your java file.
Step 4: Don't forget to add following code.
Step 5: Set your custom button click to FacebookLogin button click.
Step 6: For programmatically logout use this.
LoginManager.getInstance().logOut();
Step 7: you can find user logged in or not by profile.
(don't have enough reputation to add a comment ...)
I tried the @Shehabix's answer, can't receive callback until I add this
then it works fine.
The Simple answer is add
facebookButton.performClick()
insidecutomBtn.setOnClickListener
...
...
That will achieve this:
Complementing the answers by Harvi and Shehabix, I would suggest to add this method as this registers the authentication in Firebase Auth.
This method should be called inside "On Success" of
LoginManager
.IMO part of the selected answer is kind of work-around not the proper solution. So what needs to be changed to make it proper is the following:
Get rid of "com.facebook.login.widget.LoginButton" from your XML
Get rid of all references to the "LoginButton" in your Java code
Use Facebook's "LoginManager" class which is there for that purpose as follows: