进行WhatsApp视讯通话 [英] Place a whatsapp video call
问题描述
我使用以下代码从我的应用中发送普通的whatsapp短信:
I use this code to send a plain whatsapp text message from my app:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
如何从我的应用程序执行whatsapp视频通话?
How can I perform a whatsapp video call from my application?
推荐答案
假定您已经检索了联系电话.
Assuming you already retrieved the contact number.
第一步:,您需要从联系人中获取相应的whatsapp联系人ID.
Step1: you need to fetch the corresponding whatsapp contact id from the contacts.
String contactNumber = "Your Contact Number"; // to change with real value
Cursor cursor = context.getContentResolver ()
.query (
ContactsContract.Data.CONTENT_URI,
new String [] { ContactsContract.Data._ID },
ContactsContract.RawContacts.ACCOUNT_TYPE + " = 'com.whatsapp' " +
"AND " + ContactsContract.Data.MIMETYPE + " = 'vnd.android.cursor.item/vnd.com.whatsapp.video.call' " +
"AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%" + contactNumber + "%'",
null,
ContactsContract.Contacts.DISPLAY_NAME
);
if (cursor == null) {
// throw an exception
}
long id = -1;
while (cursor.moveToNext()) {
id = cursor.getLong (cursor.getColumnIndex (ContactsContract.Data._ID));
}
if (!cursor.isClosed ()) {
cursor.close ();
}
第2步:您使用whatsapp视频意图拨打电话.
Step2: You make the call using the whatsapp video intent.
Intent intent = new Intent ();
intent.setAction (Intent.ACTION_VIEW);
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);
注意:显然,查询代码应位于后台"线程上.以上只是如何触发whatsapp视频通话的工作摘要.
Note: Obviously the querying code should be on a Background thread. The above is just a working summary of how to fire a whatsapp video call.
哦,别忘了添加已读联系人权限
Oh, and don't forget to add the read contact permission
<uses-permission android:name="android.permission.READ_CONTACTS" />
并在运行时将其请求给您的用户,因为它被归类为危险"许可.
and request it to your users at runtime as it's classified as a "dangerous" permission.
这篇关于进行WhatsApp视讯通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!