Kimmy
Kimmy

Reputation: 486

Firebase App Invite can't send email

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.

Upvotes: 2

Views: 1525

Answers (2)

FilippoG
FilippoG

Reputation: 586

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.

Upvotes: 0

Benoit
Benoit

Reputation: 5394

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.

Upvotes: 2

Related Questions