【问题标题】:Text not passing to Whatsapp application using Intent文本未使用 Intent 传递给 Whatsapp 应用程序
【发布时间】:2015-10-19 11:08:44
【问题描述】:

我正在尝试从我的应用程序启动 whatsapp 应用程序并将一些文本传递给特定号码。 Whatsapp 应用程序正在启动,但文本无法传递。

String smsNumber = "98*******3";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, textWithClickableLink);
i.setPackage("com.whatsapp");
mContext.startActivity(i);

我的代码中是否缺少任何内容? 请帮我解决这个问题。

提前致谢!

【问题讨论】:

标签: android


【解决方案1】:

试试这个:

Uri uri = Uri.parse("smsto:" + mobileno);
Intent whatsappIntent = new Intent(Intent.ACTION_SENDTO, uri);
whatsappIntent.setPackage("com.whatsapp");

String str = "https://play.google.com/store/apps/details?id=com.example.activity&hl=en";
whatsappIntent.putExtra("sms_body", str);
      try {
          activity.startActivity(whatsappIntent);
          } catch (android.content.ActivityNotFoundException ex) {
                // Whatsapp have not been installed
         }

【讨论】:

  • 感谢您的回复,我试过了,但没有用。和之前的一样。
【解决方案2】:

你可以试试这个方法,应该可以的。我已经测试过了

private void shareWhatsApp() {
      Intent shareIntent = new Intent(Intent.ACTION_SEND);
      shareIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
      //if you have any images to share sue this, uri is the uri of image
      //shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
      //shareIntent.setType("image/*"); for image sharing
      shareIntent.setType("text/plain");
      shareIntent.setPackage("com.whatsapp");
      startActivity(shareIntent);
   }

这将启动 WhatsApp 应用程序,您必须手动选择联系人并发送。因为他们不提供我们无法自动发送的任何 SDK。

【讨论】:

    【解决方案3】:

    我试过这段代码。它使我的应用程序打开我可以发送消息的所有应用程序的列表。现在选择任何应用程序后,我可以发送我有意附加的消息。

    Intent intent = new Intent(Intent.ACTION_SEND);
                        intent.setType("text/plain");
                        intent.putExtra(Intent.EXTRA_SUBJECT, "From Stockal App");
                        intent.putExtra(Intent.EXTRA_TEXT, text);
                        mContext.startActivity(intent);
    

    感谢大家的回复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-25
      • 2016-11-20
      • 1970-01-01
      • 2013-01-21
      • 2017-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      相关资源
      最近更新 更多