Login with Facebook SDK Android

Hi,

I have some trouble with the API loginWithFacebookSdk. If I try to login in a real device the flow works well but when I try the same app in an Android emulator after a successfull login (the onActivityResult is called and I get the Facebook accessToken) neither the handleResponse nor the handleFault methods will be called.
Below you can find the code I implemented:

package com.ares.fiftapplite.activities;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ares.fiftapplite.activities.R;
import com.ares.fiftapplite.views.BarIconView;
import com.backendless.Backendless;
import com.backendless.BackendlessUser;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.local.UserTokenStorageFactory;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.ares.fiftapplite.backcallback.*;

public class OpeningActivity extends android.app.Activity {

private Intent intent;
private Button loginButton;
private TextView skip;
private FrameLayout bkg;
private CallbackManager callbackManager;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	Backendless.setUrl("https://api.backendless.com");
	Backendless.initApp(this, getResources().getString(R.string.backendless_application_key),
			getResources().getString(R.string.backendless_android_key),
			getResources().getString(R.string.backendless_version));
	setContentView(R.layout.activity_opening);
	loginButton = (Button) findViewById(R.id.loginButton);
	loginButton.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			onLoginButtonClicked();
		}
	});
	skip = (TextView)findViewById(R.id.skip_login_button);
	skip.setOnClickListener(new OnClickListener() {


		@Override
		public void onClick(View v) {
			showHomeListActivity();
		}
	});
	skip.setOnTouchListener(new OnTouchListener() {


		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
				setOrange();
			} else {
				setWhite();
			}
			return false;
		}
	});
	bkg = (FrameLayout)findViewById(R.id.bkg);
	BarIconView icon = (BarIconView)findViewById(R.id.image_title);
	icon.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			finish();	
		}
	});
	callbackManager = CallbackManager.Factory.create();
	AccessToken accessToken = AccessToken.getCurrentAccessToken();
	if(accessToken != null){
		Log.e("Login",""+accessToken.getUserId()+" - "+accessToken.getToken()+" - "+accessToken.getExpires());
		if(!accessToken.isExpired()){
			showHomeListActivity();
		} else {
			AccessToken.setCurrentAccessToken(null);
		}
	}
}
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
	super.onActivityResult(requestCode, resultCode, data);
	Log.e("Fiftapp", "on activity result - begin");
	Log.e("Fiftapp","on activity result - request code: "+requestCode);
	Log.e("Fiftapp", "on activity result - result code: "+resultCode);


	Log.e("Fiftapp", "on activity result - data: ");
	if(intent != null) {
		Bundle bundle = intent.getExtras();
		if (bundle != null) {
			Set<String> keys = bundle.keySet();
			Iterator<String> it = keys.iterator();
			while (it.hasNext()) {
				String key = it.next();
				Log.e("Fiftapp","[" + key + "=" + bundle.get(key)+"]");
			}
		}
	}
	Log.e("Fiftapp", "on activity result handling: "+callbackManager.onActivityResult(requestCode, resultCode, data));
	Log.e("Fiftapp", "on activity result - end");
}
private void setOrange() {
	skip.setTextColor(this.getResources().getColor(R.color.orange));
}


private void setWhite() {
	skip.setTextColor(this.getResources().getColor(R.color.white));
}


private static final String NAME = "name";
private static final String ID = "id";
private static final String FIELDS = "fields";
private Dialog progressDialog;
private static final String REQUEST_FIELDS =
        TextUtils.join(",", new String[] {ID, NAME});
private void onLoginButtonClicked() {
	List<String> permissions = new ArrayList<>();
	permissions.add( "email" );
	permissions.add("public_profile");
	permissions.add("user_friends");
	Map<String, String> facebookFieldMappings = new HashMap<String, String>() {{
		put("first_name", "firstname");
		put("last_name", "lastname");
		put("email", "email");
	}};


	Backendless.UserService.loginWithFacebookSdk(OpeningActivity.this, facebookFieldMappings,permissions,callbackManager, new AsyncCallback<BackendlessUser>(){




		@Override
		public void handleResponse( BackendlessUser loggedInUser ) {
			// user logged in successfully
			Log.e("FiftappLite","login successfull: "+loggedInUser.toString()+" - "+loggedInUser.getObjectId()+" - "
					+loggedInUser.getUserId()+" - "+loggedInUser.getPassword()+" - "+loggedInUser.getEmail());
			//FiftAppLiteApplication.setLogg(loggedInUser);
			showHomeListActivity();


		}


		@Override
		public void handleFault( BackendlessFault fault ) {
			// failed to log in
			Log.e("FiftappLite","fault: "+fault.getMessage());
			showBackErrorMessage(fault);
		}
	});
}


public void showErrorMessage(Exception e){
	Intent nn = new Intent(this,Msg.class);
	if(e != null){
		nn.putExtra(Msg.MESSAGE, e.toString());
	} else {
		nn.putExtra(Msg.MESSAGE, "no exc");
	}
	startActivity(nn);
}

public void showBackErrorMessage(BackendlessFault e){
	Intent nn = new Intent(this,Msg.class);
	if(e != null){
		nn.putExtra(Msg.MESSAGE, e.toString());
	} else {
		nn.putExtra(Msg.MESSAGE, "no exc");
	}
	startActivity(nn);
}

private void showHomeListActivity() {
	intent = new Intent(this, MainActivity.class);
	startActivity(intent);
	finish();
}

private SharedPreferences mPrefs;
@Override
protected void onResume() {
	this.mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
	int id = this.mPrefs.getInt("pref_key_bg_image", R.drawable.repeat_estrella);
	bkg.setBackgroundResource(id);
    Drawable bg = bkg.getBackground();
    if (bg != null) {
    	Log.e("Fiftapp","bg not null");
        if (bg instanceof BitmapDrawable) {
        	Log.e("Fiftapp","bg drawable");
            BitmapDrawable bmp = (BitmapDrawable) bg;
            bmp.mutate(); // make sure that we aren't sharing state anymore
            bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
        }
    }
	super.onResume();
}

}

Hi Alessio,

According to the Support Policy, debugging your application code is not a free option.

You may prepare a self-contained sample app (even Java app), which we could just download, run and see the problem without configuring it much. This way we could try to help you.