有很多关于WhatsApp呼叫/发送给特定用户的问题,该用户假定 READ_CONTACTS
权限 .
我们的目标是 smooth the opening of a WhatsApp video call ,来自我们的应用程序,不在我们自己的应用程序中添加/要求任何联系人权限, letting the user manually add or select the recipient user .
我似乎无法找到足够的信息来实现以下看似简单的场景之一 .
- Open the "new call" ("Select contact") activity ,就像用户触及"phone +" FAB一样 . (下面的SECOND图片的活动 . 第一张图片是显示FAB . )这就足够了,用户可以从那里添加联系人或从他们已有的联系人之一发起视频通话 . 这将是我们所需要的,但我找不到信息 .
-
或者, open WhatsApp positioning on the "Calls" tab (如上图第一张图片)
-
如果没有找到任何信息,我尝试了 opening a contact picker, getting the choosen user, and then initiate the video call with tha info ,但是:
-
调用 WhatsApp own picker ,(操作
Intent.ACTION_PICK
和类别"com.whatsapp"
)我只收到12354567@s.whatsapp.net
形式的联系人字符串,我发现无法用来发起视频通话 . 所有答案都需要"content://com.android.contacts/data/" + id
(联系人获取id
,我们无法访问) .intent.getData()
返回null,Extras中似乎只有"contact"字符串 . -
至少在某些手机上拨打 default contact picker 似乎无法正常工作 . 以下代码中的
startActivity()
什么都不做 .
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 1 && resultCode == RESULT_OK)
{
Uri result = data.getData();
Cursor cursor = getContentResolver().query(result, null, null, null, null);
if (cursor.moveToFirst())
{
//int idx = cursor.getColumnIndex(ContactsContract.ContactsContacts._ID);
// String id = cursor.getString(idx);
long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID));
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setDataAndType(
Uri.parse("content://com.android.contacts/data/" + id),
"vnd.android.cursor.item/vnd.com.whatsapp.voip.call");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
}
super.onActivityResult(requestCode, resultCode, data);
}