通过 WhatsApp 发送消息 [英] Sending message through WhatsApp
问题描述
因为我发现了一些较旧的帖子,表明 whatsapp 不支持这一点,我想知道是否发生了一些变化,以及是否有办法打开一个带有我通过一个号码发送的号码的 whatsapp '聊天'意图?
UPDATE请参考 https://faq.whatsapp.com/en/android/26000030/?category=5245251
<块引用>WhatsApp 的点击聊天"功能允许您开始聊天某人没有将他们的电话号码保存在您的手机中地址簿.只要你知道这个人的电话号码,你就可以创建一个链接,让您可以开始与他们聊天.
请勿使用:https://wa.me/+001-(555)1234567
<块引用>
示例:https://wa.me/15551234567?text=Im%20interested%20in%20your%20car%20for%20sale
原答案这是解决方案
public void onClickWhatsApp(View view) {包管理器 pm=getPackageManager();尝试 {Intent waIntent = new Intent(Intent.ACTION_SEND);waIntent.setType("text/plain");String text = "你的文本在这里";PackageInfo info=pm.getPackageInfo(com.whatsapp", PackageManager.GET_META_DATA);//检查包是否存在.如果没有,那么代码//在catch块中将被调用waIntent.setPackage(com.whatsapp");waIntent.putExtra(Intent.EXTRA_TEXT, 文本);startActivity(Intent.createChooser(waIntent, Share with"));} catch (NameNotFoundException e) {Toast.makeText(this, WhatsApp not Installed", Toast.LENGTH_SHORT).展示();}}
另见http://www.whatsapp.com/faq/en/android/28000012
Since I found some older posts, that tell that whatsapp doesn't support this, I was wondering if something had changed and if there is a way to open a whatsapp 'chat' with a number that I'm sending through an intent?
UPDATE Please refer to https://faq.whatsapp.com/en/android/26000030/?category=5245251
WhatsApp's Click to Chat feature allows you to begin a chat with someone without having their phone number saved in your phone's address book. As long as you know this person’s phone number, you can create a link that will allow you to start a chat with them.
Use: https://wa.me/15551234567
Don't use: https://wa.me/+001-(555)1234567
Example: https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
Original answer Here is the solution
public void onClickWhatsApp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Also see http://www.whatsapp.com/faq/en/android/28000012
这篇关于通过 WhatsApp 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!