2

我正在使用 Facebook SDK 向 Facebook API 发出请求。我正在尝试检索图形用户,但是我做什么并不重要。未触发回调。

如何触发片段的 OnActivityResult?

public class SampleFragment
extends Fragment
{

FacebookUtils instance;
private TextView labelText;
private ProfilePictureView prof;
private Button button;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View contentView = inflater.inflate(R.layout.fragment_sample, container, false);
    labelText = ((TextView) contentView.findViewById(R.id.label_text));
    prof = (ProfilePictureView)contentView.findViewById(R.id.selection_profile_pic);
    button= ((Button) contentView.findViewById(R.id.button));
    Bundle bundle = getArguments();
    String label = bundle.getString("label");
    labelText.setText(label);



    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Session session = Session.getActiveSession();

            if (session != null && session.isOpened()) {
                // If the session is open, make an API call to get user data
                // and define a new callback to handle the response
                Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        // If the response is successful
                        Toast.makeText(getActivity(),user.getFirstName(),Toast.LENGTH_LONG).show();
                        if (session == Session.getActiveSession()) {
                            if (user != null) {



                                prof.setProfileId(user.getId());
                                AppMsg.makeText(getActivity(),user.getFirstName(),AppMsg.STYLE_CONFIRM).show();
                                //user id
                                //profileName = user.getName();//user's profile name
                                //userNameView.setText(user.getName());
                            }
                        }
                    }
                });
                Request.executeBatchAsync(request);
            }
        }
    });
    return contentView;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);



}
4

0 回答 0