android-make whatsapp来电 [英] android-make whatsapp call

查看:182
本文介绍了android-make whatsapp来电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向特定用户发出WhatsApp电话。我试过这个并不起作用:

I want to make a WhatsApp call to a specific user. I tried this and it doesn't work:

Uri uri = Uri.parse("callto:" + phoneNUmber);
Intent i = new Intent(Intent.ACTION_CALL, uri);
i.setPackage("com.whatsapp");
startActivity(i);

我知道如何创建WhatsApp消息,代码类似且有效:

I know how to create a WhatsApp message, the code is similar and it works:

Uri uri = Uri.parse("smsto:" + phoneNUmber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(i);


推荐答案

简单的解决方案是,_id的Query ContactContract.Data和MIME类型。

Simple solution is, Query ContactContract.Data for the _id and MIME type.

ContentResolver resolver = context.getContentResolver();  
cursor = resolver.query(
            ContactsContract.Data.CONTENT_URI,
            null, null, null,
            ContactsContract.Contacts.DISPLAY_NAME);

//Now read data from cursor like 

while (cursor.moveToNext()) {
      long _id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID));
      String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
      String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));

      Log.d("Data", _id+ " "+ displayName + " " + mimeType );

}

输出将如下所示

12561 Snow vnd.android.cursor.item / vnd.com.whatsapp.profile

12561 Snow vnd.android.cursor.item/vnd.com.whatsapp.profile

12562 Snow vnd.android.cursor。 item / vnd.com.whatsapp.voip.call

12562 Snow vnd.android.cursor.item/vnd.com.whatsapp.voip.call

现在只在DB或其他地方保存那些MIME类型为vnd.android.cursor.item / vnd的_Ids。 com.whatsapp.voip.call

Now save in DB or somewhere else only those _Ids whose MIME type is vnd.android.cursor.item/vnd.com.whatsapp.voip.call

然后你就像这样的联系人发起Whatsapp电话

And then you initiate Whatsapp call with those contacts like this way

Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);

// the _ids you save goes here at the end of /data/12562     
     intent.setDataAndType(Uri.parse("content://com.android.contacts/data/_id"),
                    "vnd.android.cursor.item/vnd.com.whatsapp.voip.call");
            intent.setPackage("com.whatsapp");

startActivity(intent);

这篇关于android-make whatsapp来电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆