java - 进行whatsapp视频通话
问题描述
我使用此代码从我的应用程序发送普通的 whatsapp 文本消息:
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 视频通话?
解决方案
假设您已经检索到联系电话。
Step1:您需要从联系人中获取相应的whatsapp联系人ID。
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 视频意图拨打电话。
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视频通话的工作总结。
哦,别忘了添加读取联系人权限
<uses-permission android:name="android.permission.READ_CONTACTS" />
并在运行时向您的用户请求它,因为它被归类为“危险”权限。
推荐阅读
- c# - 如何计算 DataGridView 中列的总和
- wordpress - 为 cmb2 实现 cmb_field_map
- java - JAVA GSON日期转换器:如何将午夜作为00:00 AM而不是12:00 AM
- angular - 如何使用 IdentiyServer 4 验证 LDAP 服务,
- ionic-framework - Ionic App - 构建失败,“支持的最低 Gradle 版本为 4.4”
- python-3.x - PySpark:如何从 spark 数据框创建嵌套的 JSON?
- spring-boot - 带有可选参数的 dynamodb 查询过滤器
- c# - windows 8.1 app后台任务重启后无法工作
- sql - 在 postgres 中将 jsonb 转换为常规数组
- xml - 如何在 Odoo 10 的 Qweb 标头中获取 report_name?