I have been banging my head on this problem for a while now. I know there are other posts of a similar fashion but I cant seem to get anything to work. I have the issue where if the Facebook app is on the emulator it will not login properly.
What happens is when a user will hit the login button a small dialog will pop up and ask them if the app can get these things(permissions) from them. You hit OK and it brings you back and nothing is changed....
I look at my LOGCAT and see that it repeatedly says: Logged Out (two times) every time you hit the button.
Logging in works if FB is not installed on the emulator.
Here is my code:
FBInit - Fragment Activity Handler:
public class FBInit extends FragmentActivity {
private FBInitFragment fbInitFrag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fbinit);
final ActionBar actionBar = getActionBar();
actionBar.hide();
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
fbInitFrag = new FBInitFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fbInitFrag).commit();
} else {
// Or set the fragment from restored state info
fbInitFrag = (FBInitFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
}
findViewById(R.id.fb_init_next).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
returnIntent.putExtra("result", 1);
setResult(RESULT_OK, returnIntent);
finish();
}
});
findViewById(R.id.fb_init_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent returnIntent = new Intent();
returnIntent.putExtra("result", 1);
setResult(RESULT_CANCELED, returnIntent);
finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fbinit, menu);
return true;
}
}
FBInitFragment :
public class FBInitFragment extends Fragment {
private static final String TAG = "FBInitFragment";
private UiLifecycleHelper uiHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_fbinit, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
return view;
}
private final Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
@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);
}
}
Please advise!!
Thanks
Andy
This means your key hashes are incorrectly set in your app settings.
Please see this section on getting your key hashes and setting them correctly: https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/#create-app
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.