我正在使用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);
}