Facebook Android LoginButton更改活动

时间:2015-08-21 20:07:54

标签: android facebook facebook-login facebook-sdk-4.0

当我在登录后单击LOGIN按钮facebook更改活动时如何执行此操作?

Class MainFragment:

public class MainFragment extends Fragment implements View.OnClickListener {

private TextView mTextDetails;
private CallbackManager mCallbackManager;
private AccessTokenTracker mTokenTracker;
private ProfileTracker mProfileTracker;
private FacebookCallback<LoginResult> mCallback = new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        AccessToken accessToken = loginResult.getAccessToken();
        Profile profile = Profile.getCurrentProfile();


    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onError(FacebookException e) {

    }
};


public MainFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());

    mCallbackManager = CallbackManager.Factory.create();
    mTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken old, AccessToken newToken) {

        }
    };
    mProfileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) {

        }
    };
    mTokenTracker.startTracking();
    mProfileTracker.startTracking();



}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    return inflater.inflate(R.layout.gondola, container, false);
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    setupLoginButton(view);
}

@Override
public void onResume() {
    super.onResume();
    Profile profile = Profile.getCurrentProfile();
}

@Override
public void onStop() {
    super.onStop();
    mTokenTracker.startTracking();
    mProfileTracker.startTracking();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mCallbackManager.onActivityResult(requestCode, resultCode, data);
}

private void setupLoginButton(View view) {
    LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("user_groups", "user_photos", "user_friends"));
    loginButton.setFragment(this);
    loginButton.registerCallback(mCallbackManager, mCallback);
}


@Override
public void onClick(View v) {

}}

我想要的是:成功登录后,它会在另一项活动中快速启动一项具有退出按钮的新活动

0 个答案:

没有答案