2
我想爲Android設置Facebook登錄。我已經按照網上所有的文件來得到這個去,我的主要參考是this。Facebook登錄使用片段Android
我的代碼中沒有「錯誤」,但沒有出現任何內容,而且我確實有一種感覺,如果出現某種情況,什麼也不會發生。讓我告訴你更好的理解:
ManageFacebookFragment
public class ManageFacebookFragment extends Fragment {
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
private static final String TAG = MainScreenFragmentPagerAdapter.class.getSimpleName();
private UiLifecycleHelper uiHelper;
private final List<String> permissions;
public ManageFacebookFragment() {
permissions = Arrays.asList("user_status");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
final Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPosition = data.getInt("current_page", 0);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.settings_accounts_facebook, container,
false);
LoginButton authButton = (LoginButton) v.findViewById(R.id.authButton);
// authButton.setFragment(this);
authButton.setReadPermissions(permissions);
return v;
}
@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);
}
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...");
}
}
private final Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
}
settings_accounts_facebook.xml
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
基本上所有的我已經是按鈕,我希望能夠按獲得用戶使用Facebook進行身份驗證...現在,當我運行應用程序時,它僅僅是一個空白屏幕......我想知道這是否與片段實現有關對Facebook的登錄,不知道。任何想法或建議將不勝感激。非常感謝!
安迪