Android以编程方式断开WhatsApp视频通话

时间:2020-04-19 02:49:05

标签: android android-intent whatsapp

我已经从Android应用发起了WhatsApp个视频通话,如图here所示。

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 ();
}


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,然后开始视频通话。现在,用户返回到我的应用以继续工作流程,而视频通话作为屏幕上的覆盖继续进行。过了一会儿,我希望用户能够从我的应用程序断开WhatsApp调用。

我还可以通过编程方式从我的应用程序断开视频通话吗?否则,呼叫将继续在后台运行。

0 个答案:

没有答案