简体   繁体   English

如何通过特定联系人从其他应用程序打开Whatsapp?

[英]How to open Whatsapp from other app with a specific contact?

I've read how to open whatsapp from my app, as explained from the question How to open Whatsapp from other app - but it does not explain there how to open chat with a specific contact. 我已经阅读了如何从我的应用程序中打开whatsapp,正如如何从其他应用程序中打开Whatsapp问题中所解释的那样-但它并未解释如何与特定联系人打开聊天。 Is there any way to open chat with specific contacts? 有什么办法可以与特定联系人聊天?

You can open whats app with specific contact but that contact must have a whats app account. 您可以与特定联系人打开Whats应用程序,但该联系人必须具有Whats App帐户。

private void openWhatsApp() {
    String smsNumber = "91xxxxxxxxxx"; //without '+'
    try {
        Intent sendIntent = new Intent("android.intent.action.MAIN");
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
        sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net");
        sendIntent.setPackage("com.whatsapp");
        startActivity(sendIntent);
    } catch(Exception e) {
        Toast.makeText(this, "Error\n" + e.toString(), Toast.LENGTH_SHORT).show();
    }
}

Common mistakes with above codes are 以上代码的常见错误是

  1. ACTION_SEND not ACTION_SENDTO ACTION_SEND不是ACTION_SENDTO
  2. Very careful with contact number, It should have "91" or any other code based on the country. 请非常谨慎地使用联系电话,该电话应包含“ 91”或其他基于国家/地区的代码。
  3. Should not use any special characters like + before the number. 请勿在数字前使用任何特殊字符,例如+。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从我的 android 应用程序打开特定的 whatsapp 联系人 - open specific whatsapp contact from my android app 如何从我的 Android 应用程序通过 WhatsApp 向特定联系人发送消息? - How can I send message to specific contact through WhatsApp from my android app? WhatsApp 如何检测联系人列表中的谁使用该应用程序? - How does WhatsApp detect who from the contact list uses the app? 如何将 pdf 或图像发送给特定的 whatsapp 联系人? - How to send pdf or image to a specific whatsapp contact? 如何在Android中添加联系人,例如Skype,本机联系人应用中的whatsapp? - How to add contact in Android like skype, whatsapp in native contact app? 如何使用意图从我的应用程序打开 whatsapp 主屏幕 - how to open whatsapp home screen from my app using intents 如何在Android移动开发中的WhatsApp应用程序中访问联系方式? - How to access the contact details within the WhatsApp app in android mobile development? 如何在不使用手机号码的情况下从扫描的 QRCode 从 andorid 应用程序打开 whatsapp 聊天? - how to open whatsapp chat from andorid app from scanned QRCode without using mobile number? 使用特定联系人打开 LINE android 应用程序的聊天屏幕 - Open chat screen of LINE android app with a specific contact WhatsApp for Web如何从应用程序获取数据 - How WhatsApp for Web gets data from app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM