向 Google plus 发送邀请请求后,在 onActivityResult() 中未收到回调

Not receiving callback in onActivityResult() after sending invite request to Google plus

向 Google plus

发送邀请请求后,在 onActivityResult() 中未收到回调
public void sendGooglePlusInvite(){
Intent intent = new AppInviteInvitation.IntentBuilder(getActivity().getString(R.string.app_name))
            .setMessage(getActivity().getString(R.string.invite_message_less))
            .setCustomImage(Uri.parse(getActivity().getString(R.string.app_image_url)))
            .build();
    getActivity().startActivityForResult(intent, REQUEST_INVITE);
}

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

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (resultCode == getActivity().RESULT_OK) {
        if (requestCode == REQUEST_INVITE) {
            // Get the invitation IDs of all sent messages
            String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
            for (String id : ids) {
                Log.d("TAG", "onActivityResult: sent invitation " + id);
            }
        }
    } else {
        // Sending failed or it was canceled, show failure message to the user
        // ...
    }
}

请帮帮我

是的,您不能通过这种方式接收回调:

要在片段中获得结果,请确保在片段中调用 startActivityForResult(intent,REQUEST_INVITE); 而不是 getActivity().startActivityForResult(intent,REQUEST_INVITE);

其次确保在 activity:

中实施此方法
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
}

这将调用您片段的 onActivityResult()