【问题标题】:How to pass a specific text to a specific number through WhatsApp?如何通过 WhatsApp 将特定文本传递给特定号码?
【发布时间】:2017-06-25 21:01:28
【问题描述】:

我有这个代码。它仅使用特定数字打开 WhatsApp,而不是文本。

Uri uri = Uri.parse("smsto:" +mobilenumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", "Hello StackOverFlow");
i.putExtra("chat",true);
i.setPackage("com.whatsapp");
startActivity(i);

我尝试过使用Intent.EXTRA_TEXT,但没有结果。

如何传递文字?

【问题讨论】:

    标签: android whatsapp


    【解决方案1】:

    您不能从您的代码直接向 whatsapp 中的特定联系人发送消息。您可以将文本传递到列表屏幕,然后用户可以选择发送消息的用户。

    试试下面的代码:

     final Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
     whatsappIntent.setPackage("com.whatsapp");
     whatsappIntent.putExtra(Intent.EXTRA_TEXT, text);
     whatsappIntent.setType("text/plain");
     try {
           mContext.startActivity(whatsappIntent);
     } catch (ActivityNotFoundException ex) {
           ex.printStackTrace();
           Toast.makeText(mContext, "WhatsApp is not installed.", Toast.LENGTH_SHORT).show();
     }
    

    编辑:

    您不能向特定联系人发送 Whatsapp 消息。参考Send Whatsapp message to specific contact

    希望对你有帮助!

    【讨论】:

    • 感谢您的回复。我可以使用我的代码打开该特定号码的 whatsapp 聊天。我只需要在发送号码时发送文本。
    • 不打开whatsapp发送消息
    • 请看我的问题。我只想发送到特定号码
    • 是的,我知道你的问题,但 whasapp 不允许直接向特定号码发送消息。
    • 您提供的代码。它只打开特定的联系人聊天屏幕,但不会传递任何消息,因为 whasapp 不允许它
    猜你喜欢
    • 1970-01-01
    • 2017-07-31
    • 2016-08-30
    • 2013-09-04
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 2017-03-24
    相关资源
    最近更新 更多