如何在 Whatsapp 中将文本设置为描述(关于)?

How to set a text as a description (about) in Whatsapp?

我想在 Whatsapp 中设置文字作为描述或您的状态,例如 "available"。我使用 Intent 但如果我想通过故事分享此文本或将其发送给某人,它会在 Whatsapp 中打开一个选择页面。那是因为ACTION_SEND。是否有针对我的问题的某种类型的操作或任何解决方案?

这是我的代码

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
            whatsappIntent.setType("text/plain");
            whatsappIntent.setPackage("com.whatsapp");
            whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");

根据WhatsApp FAQ

There are two ways to integrate with WhatsApp:

-Through a custom URL scheme

-Through Android's intent system.

自定义URL方案

If you want to open a WhatsApp chat with a pre-filled message, you can use our custom URL scheme to do so. Opening whatsapp://send?text= followed by the text to send, will open WhatsApp, allow the user to choose a contact, and pre-fill the input field with the specified text.

例子

https://api.whatsapp.com/send?phone=15551234567&text=I%27m%20interested%20in%20your%20car%20for%20sale

Android意向系统

Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setPackage("com.whatsapp");
sendIntent.setType("text/plain");
startActivity(sendIntent);

使用此代码,您可以打开与给定号码的 whatsapp 聊天。

 void openWhatsappContact(String number) {
    Uri uri = Uri.parse("smsto:" + number);
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.setPackage("com.whatsapp");  
    startActivity(Intent.createChooser(i, ""));
}

您不能以编程方式设置用户状态。

您还可以查看这些以了解更多详细信息:

  1. One
  2. Two