Search code examples
androidfacebookfacebook-invite

Facebook App Invite issue


I am inviting friends using Facebook App invites but I have some problems with this.

  1. not showing push notification only show notification inside facebook notification.

  2. after sent successfully its onSuccess function not working.

Please tell me how can solve this issues.

Here is the code-:

 FacebookSdk.sdkInitialize(AppInvite.this);
                CallbackManager callbackManager = CallbackManager.Factory.create();

                FacebookCallback<AppInviteDialog.Result> facebookCallback = new FacebookCallback<AppInviteDialog.Result>() {
                    @Override
                    public void onSuccess(AppInviteDialog.Result result) {
                        Intent InviteFB = new Intent(getApplicationContext(), HomeActivity.class);
                       // InviteFB.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(InviteFB);
                        finish();
                        Log.i("TAG", "MainACtivity, InviteCallback - SUCCESS!" + result.getData());
                    }

                    @Override
                    public void onCancel() {
                        Log.i("TAG", "MainACtivity, InviteCallback - CANCEL!");
                    }

                    @Override
                    public void onError(FacebookException e) {
                        Log.e("TAG", "MainACtivity, InviteCallback - ERROR! " + e.getMessage());
                    }
                };

                AppInviteDialog appInviteDialog = new AppInviteDialog(AppInvite.this);
                if (appInviteDialog.canShow()) {
                    AppInviteContent.Builder content = new AppInviteContent.Builder();
                      content.setApplinkUrl("https://fb.me/1705244.......");
                    content.setPreviewImageUrl("");
                    AppInviteContent appInviteContent = content.build();
                    appInviteDialog.registerCallback(callbackManager, facebookCallback);
                    appInviteDialog.show(AppInvite.this, appInviteContent);

                }
            } 

Solution

    1. The invite is handled by Facebook. The recipient's Facebook app notifications settings will determine what sort of notification they will receive.

    2. I found that for the FacebookCallback to receive its callbacks, the CallbackManager must be added to onActivityResult to handle the result:

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