Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App invites using Firebase not working

Developing an App which has Firebase as backend. Currently, was stuck while implementing Firebase App Invite . Just looking to send invites ( not currently trying to implement the clicking of the dynamic link by the installed new user) but the onActivityResult returns wrong result_code

Steps followed

  • Integrated FireBase SDK and authenticating successfully.
  • Enabled Firebase Dynamic link and referred in the app
  • Clicking on the invite button shows the inbuilt Firebase Activity with option to select users to invite and sent ( SMS or Email Invites )
  • the app returns back to the invite screen as expected.

Code Snippet

InviteActivity

 btnInvite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new AppInviteInvitation.IntentBuilder(INVITATION_TITLE)
                        .setMessage(INVITATION_MESSAGE)
                        .setDeepLink(Uri.parse("https://ewyc6.app.goo.gl/eNh4"))
                        .setCallToActionText(INVITATION_CALL_TO_ACTION)
                        .build();
                startActivityForResult(intent, REQUEST_INVITE);
            }
        });

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode + "result_ok ="+RESULT_OK);

        if (requestCode == REQUEST_INVITE) {
            if (resultCode == RESULT_OK) {

                // You successfully sent the invite,
                // we can dismiss the button.
                btnInvite.setVisibility(View.GONE);

                String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
                StringBuilder sb = new StringBuilder();
                sb.append("Sent ").append(Integer.toString(ids.length)).append(" invitations: ");
                for (String id : ids) sb.append("[").append(id).append("]");
                Toast.makeText(getApplicationContext(),"Invited!!!",Toast.LENGTH_SHORT).show();

            } else {

                Toast.makeText(getApplicationContext(),"Sorry, unable to send invite.",Toast.LENGTH_SHORT).show();

            }
        }
    }

//result_code is 3 and the RESULT_OK is -1 on debugging

New to Firebase stuff , would appreciate if point out what I m doing wrong.

like image 917
user2695433 Avatar asked Oct 18 '16 11:10

user2695433


2 Answers

After hours of struggle found the issue and fixed it, posting it here since it might be helpful to others too.

The initial hint was "Create invitations failed to error code: 3" Had a similar issue here in SO Get suggested invitees failed due to error code: 3

But in my case the SHA1 certificate was already added, but the package name in Firebase turned out to be a case sensitive issue.

One more point worth taking note of, "api_key" in google-services.json downloaded from Firebase and Web Api Key are not related. I tried to copy and paste the web api key to the json file manually from dashboard to api_key under the misconception that might be the issue lead to the error.

like image 94
user2695433 Avatar answered Oct 12 '22 18:10

user2695433


  1. Log onto Firebase Console: https://console.firebase.google.com

  2. You will need to click on the "Add Fingerprint" button and then add on your SHA1 key. You do not need to redownload your google-services.json, you just need to add the SHA1 key.

  3. Try sending an app invite from your app. It will now work.

firebase

like image 27
Simon Avatar answered Oct 12 '22 19:10

Simon