Android 14 won't dial when using Intent.ACTION_CALL or Intent.ACTION_DIAL

310 Views Asked by At

After upgrading my Samsung S22 Ultra from Android 13 to Android 14, my app won't dial a phone number using Intent.ACTION_CALL or Intent.ACTION_DIAL (it did on Android 13). My app have both android.permission.CALL_PHONE and android.permission.READ_PHONE_STATE. My app is a Device Owner, but that is irrelevant to this issue.

On Android 13 the dialer opens with the phoneNumber on screen, and it is immediately dialed. On Android 14 the dialer opens with the phoneNumber on screen, but the "DIAL" or "CALL" does not happen. If the user press the "dial" button, the call is initiated.

The method is as follow:

    private fun initiatePhoneCall(context: Context, phoneNumber: String) {
        //val intent = Intent(Intent.ACTION_CALL) 
        val intent = Intent(  Intent.ACTION_DIAL)

        val uri = Uri.parse("tel:$phoneNumber")
        intent.data = uri

        if (ContextCompat.checkSelfPermission(
                context,
                Manifest.permission.CALL_PHONE
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            if (context is Activity) {
                ActivityCompat.requestPermissions(
                    context,
                    arrayOf(Manifest.permission.CALL_PHONE),
                    123
                )
            }
            return
        }
        if (context !is Activity) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }
        try {
            context.startActivity(intent) // This initiates the call directly
            Toast.makeText(context, R.string.call_divert_is_active, Toast.LENGTH_SHORT).show()
        } catch (e: Exception) {
            logger.error("initiatePhoneCall failed", e)
        }
    }

I have checked android developers site for relevant changes, and found nothing. Android 14 for devs I have checked ACTION_DIAL and ACTION_CALL for deprecation, it is not deprecated.

1

There are 1 best solutions below

1
On

Found it! Short answer: put the dial string in "" escape characters. If you are building for 14 and up AND for 13 and down, you should create cases, depending on VERSION.SDK_INT.

The AndroidTelephonyManagerImpl (or SamsungTelephonyManagerImpl in my case) block the call with the warning "dangerous MMI" (or something like that). The string override it, somehow.