[英]Android, Facebook login doesn't work when the Facebook application is installed
I'm developing an application that should be connect with facebook, I followed the facebook tutorial and insert the hash key too in the facebook dashboard. 我正在开发一个应与Facebook连接的应用程序,我遵循了Facebook教程,并将哈希键也插入了Facebook仪表板。
I was able to connect with facebook but when install the facebook application I can't connect anymore with facebook, the session state is closed. 我能够与Facebook连接,但是在安装Facebook应用程序后,我再也无法与Facebook连接,会话状态已关闭。
I read several topics but I can't find a solution that is good for my problem, so I have decide to post my question, do you have any idea regard my issue? 我读了几个主题,但是找不到适合我问题的解决方案,所以我决定发布我的问题,您对我的问题有任何想法吗?
Following my source code 按照我的源代码
public class FragmentSn extends Fragment {
private static final String TAG = "FragmentSn";
private UiLifecycleHelper uiHelper;
static boolean fbLoggedIn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragmentsn, container, false);
LoginButton authButton = (LoginButton) rootView.findViewById(R.id.authButton);
authButton.setReadPermissions(Arrays.asList("basic_info", "email"));
authButton.setFragment(this);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@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, new
FacebookDialog.Callback(){
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error,
Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
@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);
}
private 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()) {
fbLoggedIn=true;
} else if (state.isClosed()) {
fbLoggedIn=false;
}
}
}
MainActivity sourcecode MainActivity源代码
public class MainActivity extends ActionBarActivity {
// Declare Tab Variable
ActionBar.Tab Tab1, Tab2, Tab3,Tab4;
Fragment fragmentMap = new FragmentMap();
Fragment fragmentCoupon = new FragmentCoupon();
Fragment fragmentCampaign = new FragmentCampaign();
Fragment fragmentSn = new FragmentSn();
Tools tools;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
// Hide Actionbar Icon
actionBar.setDisplayShowHomeEnabled(false);
// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(false);
// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Set Tab Icon and Titles
Tab1 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_map));
Tab2 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_coupon));
Tab3 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_campaign));
//Tab4 = actionBar.newTab().setIcon(this.getResources().getDrawable(R.drawable.tab_sn));
// Set Tab Listeners
Tab1.setTabListener(new TabListener(fragmentMap));
Tab2.setTabListener(new TabListener(fragmentCoupon));
Tab3.setTabListener(new TabListener(fragmentCampaign));
//Tab4.setTabListener(new TabListener(fragmentSn));
// Add tabs to actionbar
actionBar.addTab(Tab1);
actionBar.addTab(Tab2);
actionBar.addTab(Tab3);
//actionBar.addTab(Tab4);
// Facebook - START
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
fragmentSn = new FragmentSn();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fragmentSn)
.commit();
} else {
// Or set the fragment from restored state info
fragmentSn = (FragmentSn) getSupportFragmentManager().findFragmentById(android.R.id.content);
}
// Facebook - END
// AM 2014/01/15 - START
//Check update information
tools = new Tools(this.getApplicationContext());
// AM 2014/01/15 - END
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
look forward your reply, thanks 期待您的回复,谢谢
I've encountered this before too and recreating the debug key resolved this issue for me. 我之前也遇到过这个问题,重新创建调试密钥为我解决了这个问题。 Note you can add multiple keys on the Facebook app profile, you will probably want to add at least the debug key from all development machines and the release key. 请注意,您可以在Facebook应用程序配置文件中添加多个密钥,您可能希望至少从所有开发机中添加调试密钥以及发布密钥。
I don't know why, but after recreate the key ashes in the same way that I did until now and insert in the facebook dashboard the program start to receive correctly the information by facebook application. 我不知道为什么,但是在以与现在相同的方式重新创建了骨灰之后,将程序插入到Facebook仪表板中,程序开始正确接收Facebook应用程序的信息。
Thanks chintak khetiya for your replies. 感谢chintak khetiya的回复。
Are you using the emulator? 您在使用模拟器吗? If so, try the ARM version. 如果是这样,请尝试使用ARM版本。 Facebook LoginActivity crashes on the Intel emulator. Facebook LoginActivity在Intel模拟器上崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.