[英]Login to facebook does not work if facebook app is installed on emulator - Android 4.3
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.
我有一个问题,如果Facebook应用程序在模拟器上,它将无法正确登录。
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. 我看一下我的LOGCAT,发现它反复显示:每次按下按钮时注销(两次)。
Logging in works if FB is not installed on the emulator. 如果仿真器上未安装FB,则登录有效。
Here is my code: 这是我的代码:
FBInit - Fragment Activity Handler: FBInit-片段活动处理程序:
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 : 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 请参阅有关获取和正确设置密钥哈希的这一部分: https : //developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/#create-app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.