I'm trying to implement the Facebook LoginButton using the tutorial here https://developers.facebook.com/docs/android/login-with-facebook/v2.0#step2
The problem is on the line authButton.setFragment(this);
.
I'm using native fragments (android.app.Fragment) but setFragment expects a support Fragment (android.support.v4.app.Fragment).
EDIT: I cannot switch to support Fragments, I have a big app that uses native Fragments.
I think the solution you are looking for is the wrapper class below. Using this you can just call
The wrapper is a support fragment and just passes the method calls from the facebook LoginButton to the native fragment. I'm using this and it works fine.
The reason is obvious. Facebook SDK is using the Fragment class from the support library for making it backward compatible and work with older versions of android (API Level < 11). And you must use the same class in your application as well.
Include the support library
android-support-v4.jar
in to thelibs
folder and use the Fragment class from it (for Ant based projects). If you are using Gradle build system, Follow the instruction given in Lei's answer above.Update: If your application have high dependency with native library, then you are left with a single option. The Facebook SDK code is available here. Fork it and change the SDK to use native library (Remove the support library from the SDK itself). But keep in mind that, your application will be limited to run on API level greater than 10 (minSdkVersion should be 11).
Add this below in you build.gradle file
Then import android.support.v4.app.Fragment instead of the native fragment.
I solved this issue by using the activity context instead of the fragment context and passing the "onActivityResult" from the Activity, to the fragment to the callbackManager.
Just follow the following instructions:
Add the following method inside the activity of your fragment, to catch and pass any result to the fragment:
Override onActivityResult also inside your fragment which contains the LoginButton and pass the result to the callbackManager.
I hope it works.
Follow these steps:
Remove import android.app.Fragment;
Add import android.support.v4.app.Fragment;
Right click on your Project and Select properties.
Build Path > Library > Add External Library > Locate your android-support-v4.jar file(sdk > extras > android > supports > v4)