通过Android Intent发送链接到Whatsapp [英] Send link to Whatsapp via Android Intent

查看:627
本文介绍了通过Android Intent发送链接到Whatsapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从我的android应用程序发送带有链接的文本消息,以聊天应用程序(如Whatsapp或SMS消息).

I'm trying to send a text message with a link from my android app to chat applications like Whatsapp or SMS message.

这些应用程序不接受text/html类型作为Intent类型,当我使用text/plain类型时,我发送的消息仅包含主题,而没有消息的正文.

These apps don't accept text/html type as an Intent type and when I'm using text/plain type my message is being sent with the subject only and without the message's body.

我见过可以通过Whatsapp共享链接的应用程序,例如Chrome和Dolphin Browser应用程序.

I've seen apps that can share links via Whatsapp like Chrome and Dolphin Browser apps.

这是我的代码:

    @JavascriptInterface
    public void sendMessage(String trip) {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Trip from Voyajo");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("I've found a trip in Voyajo website that might be interested you, http://www.voyajo.com/viewTrip.aspx?trip=" + trip));
        startActivity(Intent.createChooser(emailIntent, "Send to friend"));
}

推荐答案

@JavascriptInterface
    public void sendMessage(String trip) {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Trip from Voyajo");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("I've found a trip in Voyajo website that might be interested you, http://www.voyajo.com/viewTrip.aspx?trip=" + trip));
        emailIntent.setType("text/plain");
        startActivity(Intent.createChooser(emailIntent, "Send to friend"));
}

在这里,我只是更改emailIntent.setType("text/plain");这条线的位置,并且可以工作. 您可以在邮件应用程序正文电子邮件应用程序主体中获得链接.但是在这里,您只能在邮件应用程序中获得主题文本,而不能在邮件应用程序中获得主题文本,但是您可以在正文中获得链接,从而实现目标...

here i just change position of emailIntent.setType("text/plain"); this line and it works. you get your link in messaging app body email app body.but here you can get subject text only in Mail apps not in messaging app but you can get your link in body so achive your goal...

就这样...

这篇关于通过Android Intent发送链接到Whatsapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆