2

I set up Firebase App Invite, after selecting the contacts, it shows a snackbar saying:

Your invitation has been sent

In onActivityResult, it returns me a RESULT_OK, but when I check the ids by

String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
Logger.INSTANCE.LogD(TAG, "onActivityResult: ids.size = " + ids.length );

it says the ids.length == 0.

Why it cannot returns ids but returns a RESULT_OK?

Sometimes I can receive SMS invitations, but I can never receive email invitation.

Here is my gradlew:

compile 'com.google.firebase:firebase-invites:9.6.1'
apply plugin: 'com.google.gms.google-services'
classpath 'com.google.gms:google-services:3.0.0'

App Invite function:

Intent i = new AppInviteInvitation.IntentBuilder(getString(R.string.share_title))
                .setMessage(getString(R.string.share_content))
                .setEmailHtmlContent(
                        "<html>\n" +
                        "<body>\n" +
                        "\t<a href=\""+getString(R.string.share_link)+"\">Download</a>\n"+
                        "</body>\n" +
                        "</html>")
                .setEmailSubject(getString(R.string.share_title))
                .build();
        startActivityForResult(i, REQUEST_INVITE);

Anyone have any idea why I can't receive email invitations? And my SMS invitation is not stable as well.

Kimmy
  • 446
  • 1
  • 4
  • 9
  • I have exactly the same problem. In my case, it was OK previously but now it does not work anymore. I suspect it's related to email HTML content value, that I changed. I keep you posted. – Benoit Nov 23 '16 at 11:22

2 Answers2

2

The problem is that, for some reason, when emailHtmlContent does not contains valid html, Firebase just fails silently. IMHO, it should validate this when the intent is created, and throw an exception if it is not correct.

Difficult to precisely say what is wrong in your html, it is quite hard to read with escaped double quotes. I will rather describe my solution :

Put html in a resource file, like this: (Note the the CDATA that let you put html in an xml file without the need for escaping):

<resources>
    ...
    <string name="invitation_email_html_content"><![CDATA[<!DOCTYPE html>
<html>
    <body>
        <div>
            <a href="%%APPINVITE_LINK_PLACEHOLDER%%">Install My App</a>
        </div>
    </body>
</html>]]></string>
</resources>

You build the intent as this :

            Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                    .setEmailSubject(getString(R.string.invitation_email_subject))
                    .setMessage(message)
                    .setEmailHtmlContent(getString(R.string.invitation_email_html_content))
                    .build();
            startActivityForResult(intent, REQUEST_INVITE);

I also think it's better to let firebase generate the link for you (as I did, put %%APPINVITE_LINK_PLACEHOLDER%% in your html), it is more portable solution: in this case it will trigger the standard behavior when clicked : Install the app if not yet installed, or launch the MainActivity if already installed. But that may not meet your specific needs.

Benoit
  • 5,118
  • 2
  • 24
  • 43
  • Thanks for answering! I tried this method but it still doesn't work.. I personally think the main reason is somehow Firebase failed when the html embed the deep link firebase generated e.g. `install`. Because after I changed the link to another normal link tha start with "www." such as `www.google.com`, it can send the email. (sounds so weird and doesn't make sense to me) – Kimmy Nov 24 '16 at 00:35
  • Then you may try to "cheat" a bit by including this line in your html : ``. Commented out, it should never be seen or used by email recipients. – Benoit Nov 24 '16 at 13:33
0

In my case, I have removed .setOtherPlatformsTargetApplication(...) and emails get sent again. It messes up the link on other platform when app is not installed htough.

FilippoG
  • 546
  • 3
  • 16