简体   繁体   中英

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>

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.

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));

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM