[英]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 以上代码的常见错误是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.