android - 通过 WhatsApp 按 Intent 发送消息

标签 android android-intent send whatsapp

我如何将按摩从我的应用程序发送到 whatsapp 中的特殊号码,我知道这个代码可以将按摩分享到群组或 whatsapp 上的联系人

Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Sorry For Interruption,I'm Just Trying Something";
waIntent.setPackage("com.whatsapp");

if (waIntent != null) {
    waIntent.putExtra(Intent.EXTRA_TEXT, text);//
    startActivity(Intent.createChooser(waIntent,"Share with"));

但我想发送消息到特殊号码,如“966xxxxxxx”,我该怎么做?

最佳答案

这是一个解决方案:

private void openWhatsApp(String id) {

Cursor c = getSherlockActivity().getContentResolver()
            .query(ContactsContract.Data.CONTENT_URI,
                  new String[] { ContactsContract.Contacts.Data._ID },  
                  ContactsContract.Data.DATA1 + "=?",
                  new String[] { id }, 
                  null);

c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW, 
              Uri.parse(
                   "content://com.android.contacts/data/" +           
                    c.getString(0)));

startActivity(i);
c.close();
}

id 是什么应用程序 uri,如 966123456789@s.whatsapp.net

关于android - 通过 WhatsApp 按 Intent 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17768688/

相关文章:

javascript - Node js : receive data from client

android - RxJava 分页

java - 检查互联网连接 OKHTTP

java - 如何使用 public <T extends View> T findViewById(int id);在Android Activity中编译sdk 26?

delphi - 使用 Indy 向 Gmail 地址发送电子邮件会被视为垃圾邮件

java - 使用sinch在java中发送短信

android - 从 android youtube 播放器 api 中获取大量崩溃

android - 注册 Android 应用程序以接收某些文件类型

java - 在java中的线程和标志之间交换多个对象

android - 当 Activity 销毁时再次调用 onStart 的服务