Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android-make whatsapp call

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

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);
like image 971
israelbenh Avatar asked Jul 29 '16 09:07

israelbenh


People also ask

Why can't I make calls on WhatsApp Android?

When experiencing issues with WhatsApp calls, please try connecting to a different network (such as Wi-Fi connection instead of mobile data, or vice versa). Your current network might not be properly configured for UDP (User Datagram Protocol) which may prevent WhatsApp Calling from functioning properly.

How can I make a call using WhatsApp?

Open the conversation of the person you'd like to call and tap the call button in the top-right corner of the screen. Tap the Contacts tab at the bottom of the screen, then tap the name of the person you'd like to call. That person's contact information will appear. Tap the call button.

Can you call a WhatsApp number from a regular phone?

Similarly, you cannot place calls to regular numbers (including both landlines and cell phones). This is different from Skype and smartphone apps that specialize in VOIP-to-phone calls. Secondly, although WhatsApp Web integrates with your phone's WhatsApp app, it has no support for WhatsApp calls.

How do I answer WhatsApp call on android?

Answer and Reject WhatsApp Calls On Android, tap on the Answer button if the phone is unlocked. If the phone is locked, you will see a different calling screen. Swipe up from the green button to accept the call. Swipe up on the red button to reject the call.


1 Answers

Answer provided by @Adnan Khan works in Android 11, but I wanted to provide the Kotlin version of his answer:

val resolver: ContentResolver = requireContext().contentResolver
val cursor: Cursor? = resolver.query(
    ContactsContract.Data.CONTENT_URI,
        null, null, null,
    ContactsContract.Contacts.DISPLAY_NAME)

while(cursor!!.moveToNext()) {
    val _id: Long = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data._ID))
    val displayName: String = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME))
    val mimeType: String = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE))

    Log.i("Intents", "$_id $displayName $mimeType")

Now, the intent in Kotlin goes like this: _id is the value you get from the previous routing

val intent = Intent()
intent.action = 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)

Last but not least add the following to the AndroidManifest.xml:

<uses-permission
    android:name="android.permission.CALL_PHONE"
    androd:maxSdkVersion="30" />
<uses-permission
    android:name="android.permission.READ_CONTACTS"
    androd:maxSdkVersion="30" />

After this, you need to go to Settings -> Apps -> Select your app and mark the two permissions as allowed.

There should be a way that the app ask you the first time it is run, but that is another topic.

like image 106
Wilder Avatar answered Sep 23 '22 17:09

Wilder