I am using facebook sdk to let the user post a message to his wall.
I was using the existing facebook tutorial:
Facebook tutorial
Here the main code which I use:
package com.greatapp;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("YOUR_APP_ID");
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
* Get existing access_token if any
*/
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {}, new DialogListener() {
#Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
}
I have extended this base code with a postToWall(String message) method. This is working fine.
I call this by an intent from an other activity. I want that all this facebook posting is handled in the background without showing an progressbar or something like that. Is this possible?
The facebook android SDK has two facebook classes to use: https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/AsyncFacebookRunner.java
You can use it exactly the same way as the other one, just to construct it you do this:
Facebook fb = new Facebook(appid);
AsyncFacebookRunner async = new AsyncFacebookRunner(fb);
async.request("me", new SimpleDialogListener());
Related
Is it possible to do a Facebook Login in Android in an non-Activity class?
I have an activity which loads different "Setting Classes" for Social Media Logins etc.
One of them is Facebook. This is a non Activity class which loads my Facebook-Settings.xml. There are some Switch Buttons etc. Save switch button status is working.
I have also integrated the Facebook Login Button. But it seems the onSuccess is not called
What am I missing or doing wrong here? Is it even possible to login to Facebook in a non-activity class?
public class FacebookService extends SensorService {
public FacebookService() {
super("fb");
}
//add Sensorname UI
#Override
public void load() {
name.setText("FACEBOOOK");
}
//load settings xml-file if settings button is clicked
#Override
public int getSettingsViewId() {
FacebookSdk.sdkInitialize(context.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
}
return R.layout.fb_settings;
}
//Saves Checked Buttons from Facebook Seetings
#Override
public void save(View settings) {
TextView text = (TextView) settings.findViewById(R.id.FBText);
switchPosts = (Switch) settings.findViewById(R.id.switchPosts);
}
//Creates View for Facebook Settings
//loads Check Buttons state from Shared preferences and updates view
#Override
public void createSettings(View settings) {
LoginButton loginButton = (LoginButton) settings.findViewById(R.id.login_button);
loginButton.setReadPermissions("public_profile, email, user_about_me, user_posts, user_friends, user_events, user_photos, user_likes, user_relationships, user_birthday");
getLoginDetails(loginButton);
}
protected void getLoginDetails(LoginButton login_button){
// Callback registration
login_button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult login_result) {
Log.d("app", "FB Login");
accessToken = login_result.getAccessToken();
if(accessToken != null){
//statusFacebook.setText("Login Erfolgreich");
Log.d("app", "Login success");
}
else{
//statusFacebook.setText("Login fehlgeschlagen");
Log.d("app", "Login no success");
}
}
#Override
public void onCancel() {
// code for cancellation
}
#Override
public void onError(FacebookException exception) {
// code to handle error
}
});
}
private void setSwitches() {
//DO Something
}
}
I start the FacebookService.class from my Main Activity
protected void onCreate(Bundle savedInstanceState) {
....
ServiceManager.getInstance().setContext(this);
ServiceManager.getInstance().setRoot((ViewGroup)findViewById(R.id.service_view));
ServiceManager.getInstance().add(new FacebookService());
ServiceManager.getInstance().add(new TwitterService());
}
You receive the result of login into onActivityResult method of your Activity or Fragment. Then into that method you must pass the result to the CallbackManager. This step is not automatic.
So you need something like this (this the Fragment's method)
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
If you want to implement login in non Activity class you must anyway add at least this code
There is no documentation about it, but technically it is possible. Here is how I achieved this:
This is my MainActivity:
package com.saddan.facebook_login_mvc;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.login.widget.LoginButton;
public class MainActivity extends AppCompatActivity
{
LoginButton loginButton;
private FacebookLogin Login;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton=findViewById(R.id.login_button);
Login=new FacebookLogin(loginButton,this);
Login.facebookLogin();
Login.checkLoginStatus();
}
#Override
protected void onActivityResult(int requestCode, int resultCode,#Nullable Intent data) {
Login.onActivityResultFB(requestCode,resultCode,data);
super.onActivityResult(requestCode, resultCode, data);
}
}
And my Facebook Login Class is:
package com.saddan.facebook_login_mvc;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
public class FacebookLogin
{
private LoginButton loginButton;
private Context context;
private CallbackManager callbackManager;
public FacebookLogin(LoginButton loginButton, Context context)
{
this.loginButton = loginButton;
this.context = context;
}
public void facebookLogin()
{
callbackManager = CallbackManager.Factory.create();
loginButton.setPermissions(Arrays.asList("email","public_profile","user_friends"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
{
#Override
public void onSuccess(LoginResult loginResult)
{
Toast.makeText(context, "Login successfull", Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel()
{
Toast.makeText(context, "cancel", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(FacebookException error)
{
Toast.makeText(context, "error log", Toast.LENGTH_SHORT).show();
}
});
}
public void onActivityResultFB(int requestCode, int resultCode, Intent data)
{
callbackManager.onActivityResult(requestCode, resultCode,data) ;
}
AccessTokenTracker accessTokenTracker=new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken)
{
if(currentAccessToken==null)
{
Toast.makeText(context,"User Logged out",Toast.LENGTH_LONG).show();
}
else
loadUserProfile(currentAccessToken);
}
};
private void loadUserProfile(AccessToken newAccessToken)
{
GraphRequest request = GraphRequest.newMeRequest(newAccessToken, new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response)
{
try {
String first_name = object.getString("first_name");
String last_name = object.getString("last_name");
String email = object.getString("email");
String id = object.getString("id");
String image_url = "https://graph.facebook.com/"+id+ "/picture?type=normal";
Log.d("Name", first_name+" "+last_name);
Log.d("email", email);
Log.d("image", image_url);
} catch (JSONException e)
{
e.printStackTrace();
Toast.makeText(context, "exception", Toast.LENGTH_SHORT).show();
Log.d("Error_fb","fb"+e.getMessage());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","first_name,last_name,email,id");
request.setParameters(parameters);
request.executeAsync();
}
public void checkLoginStatus()
{
if(AccessToken.getCurrentAccessToken()!=null)
{
loadUserProfile(AccessToken.getCurrentAccessToken());
}
}
}
One thing you really need to concentrate is onActivityResult method, which you can't use to any normal class,see my MainActivity and my Facebook login class how I override onActivityResult for facebook login.
If you are useing Fragment instead of Activity you can initialize like this
loginButton.setFragment(this);
Login=new FacebookLogin(loginButton,getActivity());
I am developing an android app, where the user should be able to log in with a Facebook account. The application has worked in the first 5-10 min. I could see the layout where i was prompted to give/deny permissions.
When i try to log in, it shows me the "Loading" message from Facebook API but then returns to the previous layout.
The error message i receive is: "Should not pass a read () permission to a request for publish or manage authorization".
I appreciate any help to resolve this issue..
package com.kampusbilisim.sencebence;
import java.io.*;
import java.net.*;
import org.json.*;
import com.facebook.android.*;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.Facebook.DialogListener;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.*;
import android.util.Log;
import android.view.*;
import android.widget.*;
#SuppressWarnings("deprecation")
public class FullscreenActivity extends Activity {
String TAG = "SenceBence";
private static String APP_ID = "659712077445489";
private Facebook facebook;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
Button btnFbLogin;
private AsyncFacebookRunner mAsyncRunner;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_fullscreen);
facebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
btnFbLogin = (Button) findViewById(R.id.button1);
btnFbLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
loginToFacebook();
Toast.makeText(FullscreenActivity.this, "Logging in.. ", Toast.LENGTH_SHORT).show();
}
});
TextView tv = (TextView) findViewById(R.id.girisyazisibeyaz);
tv.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/AvenirNextLTPro-Bold.otf"));
}
#SuppressWarnings("deprecation")
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] { "email" , "publish_actions", "publish_checkins", "publish_stream" },
new DialogListener() {
#Override
public void onCancel() {
// Function to handle cancel event
}
#Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
#Override
public void onError(DialogError error) {
// Function to handle error
}
#Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
}
}
I am doing a module of my project where i need to complete login with facebook and get basic details like state,name,email...
I followed the following tutorials
https://developers.facebook.com/docs/android/login-with-facebook
https://stackoverflow.com/questions/20744927/access-profile-details-from-facebook-login-in-android
and others..
I am able to execute them but even after showing the alert message saying this want to acess details.. The "state" is not getting created..
I got to know this by state.isOpened function..
Can any one help....
Intent it=new Intent(getApplicationContext(),FacebookLogin.class);
startActivity(it);
FacebookLogin class:
package com.firstandroid.app;
import java.util.Arrays;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;
import com.facebook.widget.LoginButton;
public class FacebookLogin extends Activity{
private static final String TAG = "FacebookLogin";
private UiLifecycleHelper uiHelper;
private Session session;
GraphUser user;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LoginButton authButton = (LoginButton)findViewById(R.id.authButton);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status"));
authButton.setReadPermissions(Arrays.asList("email"));
uiHelper = new UiLifecycleHelper(FacebookLogin.this, callback);
uiHelper.onCreate(savedInstanceState);
// String id=user.asMap().get("email").toString();
// String name= user.getLastName();
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
// user has either logged in or not ...
// make request to the /me API
Request request = Request.newMeRequest(this.getSession(),
new Request.GraphUserCallback() {
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user,
Response response) {
// TODO Auto-generated method stub
if (user != null) {
// TextView welcome = (TextView) findViewById(R.id.welcome);
//welcome.setText("Hello " + user.getName() + "!");
Log.e("user fname",user.getFirstName());
Log.e("user lname",user.getLastName());
Log.e("user username",user.getUsername());
Log.e("user email",(String)user.getProperty("email"));
}
}
});
Request.executeBatchAsync(request);
}
else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
public final Session getSession() {
return this.session;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
#Override
public void onResume() {
super.onResume();
// For scenarios where the main activity is launched and user
// session is not null, the session state change notification
// may not be triggered. Trigger it if it's open/closed.
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
}
You need to call onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
So when login done . It comes to same activity and calls status callback with session state is opened
initialize UiLifecycleHelper
private UiLifecycleHelper uiHelper;
in oncreate need to call before setContentView
uiHelper = new UiLifecycleHelper(this, statusCallback);
uiHelper.onCreate(savedInstanceState);
and need to maintain session in
#Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
}
#Override
protected void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
protected void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
Source link:
link
I am facing a problem when logging into Facebook using my app, It shows following error
"App Not Setup : The Developer of this App have not setup this app properly for facebook login "
This is my code :
package com.example.dronacharyaratings;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class login extends ActionBarActivity implements OnClickListener {
ImageButton imgbtn;
// Your Facebook APP ID
private static String APP_ID = "578242662259998"; // Replace with your App ID
// Instance of Facebook Class
#SuppressWarnings("deprecation")
private Facebook facebook = new Facebook(APP_ID);
#SuppressWarnings({ "deprecation", "unused" })
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
#SuppressWarnings("deprecation")
public void onCreate(final Bundle savedInstanceState1) {
super.onCreate(savedInstanceState1);
setContentView(R.layout.login);
getSupportActionBar().hide();
mAsyncRunner = new AsyncFacebookRunner(facebook);
imgbtn = (ImageButton)findViewById(R.id.imageButton1);
imgbtn.setOnClickListener(this);
}
public void onClick(View arg0) {
Log.d("Image Button", "button Clicked");
loginToFacebook();
}
#SuppressWarnings("deprecation")
private void loginToFacebook() {
// TODO Auto-generated method stub
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
Log.d("FB Sessions", "" + facebook.isSessionValid());
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
#Override
public void onCancel() {
// Function to handle cancel event
}
#Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
});
}
}
#SuppressWarnings("deprecation")
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
/**
* Function to show Access Tokens
* */
public void showAccessTokens() {
#SuppressWarnings("deprecation")
String access_token = facebook.getAccessToken();
Toast.makeText(getApplicationContext(),
"Access Token: " + access_token, Toast.LENGTH_LONG).show();
}
}
This issues only arises when your app isn't public.
To do that you should first login into your
developers.facebook.com
and in the status and review of your particular app
Toggle the button to yes where it says "Do you want to make
this app and all its live features available to the general
public? "
You are getting this error probably because your app is not public and only you as an admin have the access to login.For making the app as public and allowing others to use your app do the following steps.
1)Make sure you have a valid email in the "Contact Email" field in the settings -> Basic section.
2)Once you provide a valid e-mail then only you can make your app as public so that FB can contact you regarding your app.
3)In the "Status and Review" section change the option of "Do you want to make this app and all its live features available to the general public?" from "no" to yes and press confirm on the popup message.
you can see a red dot just next to your app name which confirms that your app is now available to public and all can login with their own credentials.
Happy facebooking!!!
I am developing a Facebook Android integration using the below code, but once I log-in through this app then it does not logout from facebook even if I logout from Facebook app or browser both from my device. So this android app can still post on my Facebook wall. How do I logout from this app if I logout from my facebook app or facebook on browser.
package com.facebook.androidhive;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
public class AndroidFacebookConnectActivity extends Activity {
// Your Facebook APP ID
private static String APP_ID = "APP_ID"; // Replace with your App ID
// Instance of Facebook Class
private Facebook facebook = new Facebook(APP_ID);
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mAsyncRunner = new AsyncFacebookRunner(facebook);
loginToFacebook();
postToWall();
}
/**
* Function to login into facebook
* */
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
Log.d("FB Sessions", "" + facebook.isSessionValid());
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
#Override
public void onCancel() {
// Function to handle cancel event
}
#Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
}
#Override
public void onError(DialogError error) {
// Function to handle error
}
#Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
/**
* Function to post to facebook wall
* */
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
}
#Override
public void onError(DialogError e) {
}
#Override
public void onComplete(Bundle values) {
}
#Override
public void onCancel() {
}
});
}
/**
* Function to Logout user from Facebook
* */
public void logoutFromFacebook() {
mAsyncRunner.logout(this, new RequestListener() {
#Override
public void onComplete(String response, Object state) {
Log.d("Logout from Facebook", response);
if (Boolean.parseBoolean(response) == true) {
runOnUiThread(new Runnable() {
#Override
public void run() {
}
});
}
}
#Override
public void onIOException(IOException e, Object state) {
}
#Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
#Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
#Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}
}
You can't force a logout from your app if you logout of the Facebook app, at least no API that we support with our SDK.
In theory, you could find a way to attach some sort of uninstall intent or to parse logs for any messages regarding facebook logout, but it generally is not recommended as best practice to force a logout of another app when another app logs out (its not intuitive to the user that this is going to happen).
try remove this code
if (access_token != null) {
facebook.setAccessToken(access_token);
Log.d("FB Sessions", "" + facebook.isSessionValid());
}