Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email with link to open Android application

I have created some code that emails an html email to a given address. The email contains a link like the following:

<a href="crystalcloud://android?4567">Click to validate account</a>

I was testing this by sending it to my gmail account. For some reason, when I receive the email, it will not let me click on the link. If I put this link in a web page, my application starts up fine.

Is there something special I have to do to get this link to show up in an email, or goes gmail just block these kind of links? Is there anyway to get around this issue in gmail?

EDIT: Added snippets of my code

Code to send link:

    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailAddress));
    message.setSubject("New Crystal Cloud User");
    message.setContent("Thank you for creating a new Crystal Cloud account!<br><a href=\"crystalcloud://android?4567">Click to validate account</a>", "text/html; charset=utf-8");
    Transport transport = session.getTransport("smtp");
    transport.connect(host, from, pass);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();

Android code to respond to intent:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="crystalcloud" />
        </intent-filter>
like image 307
Nick Banks Avatar asked Apr 18 '11 02:04

Nick Banks


1 Answers

This is a problem with the android email clients that they don't show links as clickable unless they are http or https.

My solution was to use a http scheme to open my app:

<data android:scheme="http" android:host="com.company.app" android:port="3513" />

This works but in annoying because it prompts the user to open the app in either the browser or your application. Another solution is to have a link to a website that then does a javascript redirect to your app though this can cause more problems.

like image 186
skorulis Avatar answered Sep 22 '22 00:09

skorulis