10

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>
Nick Banks
  • 4,298
  • 5
  • 39
  • 65

3 Answers3

16

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.

skorulis
  • 4,361
  • 6
  • 32
  • 43
0

I am facing same problem at last i got solution. You can able to share text as well as link

  String link_val = "http://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName();
        String body = "<a href=\"" + link_val + "\">" + link_val + "</a>";
        String data = "Hello I am using this App.\nIt has large numbers of Words meaning with synonyms.\nIts works offline very smoothly.\n\n" + body;
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(data));
Binesh Kumar
  • 2,763
  • 1
  • 16
  • 23
  • does it work on android 6 and beyond? I tried something similar, it works for android 4.3 but not on 6 and 7 :| – rosu alin Jan 16 '17 at 16:21
  • It will be working , because i have used same code , you can try it – Binesh Kumar Jan 17 '17 at 03:54
  • I tried it and it doesn't. From a S3mini I get in my email the links, from a Nexus 5 with 6 and a LG G5 with 7 I just get text, no hyperlinks. I tried with type: "text/html" and "message/rfc822" Any ideea why? – rosu alin Jan 17 '17 at 09:03
0

In your mail header put in Content-Type: text/html to indicate that the content is in HTML to indicate that the mail is coming in HTML format. Then the mail client will render the HTML appropriately. It will help to enclose the link in a <html></html> block as well.

Rasika
  • 1,980
  • 13
  • 19
  • I already did that. The html is being sent correctly, but it seems to be blocking this type of link. Any ideas? – Nick Banks Apr 18 '11 at 02:26
  • Is it only happening in Gmail? Have you tried with other mail clients? If it is only with Gmail, it could be to do with its Phishing filter. – Rasika Apr 18 '11 at 02:36