Neither user 10022 nor current process has android.permission.READ_PHONE_NUMBERS

1k Views Asked by At

Why this code snippet need READ_PHONE_NUMBERS permission?

 val manager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
        val connectionServiceId = getConnectionServiceId()
        val componentName =
            ComponentName(applicationContext, PhoneConnectionService::class.java)
        val phoneAccountHandle = PhoneAccountHandle(componentName, connectionServiceId)

here it causes the error.

phoneAccount = manager.getPhoneAccount(phoneAccountHandle)

Requires Permission: Manifest.permission.READ_PHONE_NUMBERS for applications targeting API level 31+.

but i am not accessing the phone from device I just created that manually like this.

val builder = PhoneAccount.builder(
                phoneAccountHandle,
                this.resources.getText(R.string.app_name)
            )
            val uri = Uri.parse("tel:1236547")
            builder.setSubscriptionAddress(uri)
            builder.setAddress(uri)
            builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
            phoneAccount = builder.build()
            manager.registerPhoneAccount(phoneAccount)

So how can use this code or do this same process without READ_PHONE_NUMBERS permission?

1

There are 1 best solutions below

5
Mohammad Taqi On

I found the solution.

I just removed this line because it is not much needed.

phoneAccount = manager.getPhoneAccount(phoneAccountHandle)

Without this line, the code works properly without any permission.