我跟随official login tutorial,突然之间我遇到了错误。我是android的新手,所以我有点困惑。所以,这是我的FBMainFragment
,如MainFragment
官方教程:
public class FBMainFragment extends android.support.v4.app.Fragment {
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
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.social_networks, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.FB_Login);
authButton.setFragment(this);
return view;
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(MenuActivity.TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(MenuActivity.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);
}
...这里是我的SocialNetworksActivity
类MainActivity
。文档:
public class SocialNetworksActivity extends FragmentActivity {
private FBMainFragment fbMainFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
fbMainFragment = new FBMainFragment();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, fbMainFragment)
.commit();
} else {
// Or set the fragment from restored state info
fbMainFragment = (FBMainFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
}
}
如您所见,我还没有完成教程。现在我在2部分的末尾。但是,正如它所说,构建并运行您的项目。使用Facebook登录。您应该通过权限屏幕。。所以我试着运行我的项目和我的应用程序只是觉得。有任何想法吗? ;)
答案 0 :(得分:0)
我刚刚在清单中添加了此代码,现在一切正常。 @PankajNimgade,谢谢你的帮助。
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/FB_AppID"/>
P.S FB_AppID
是我的Facebook应用ID