Reputation: 179
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?
Upvotes: 0
Views: 1361
Reputation: 179
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.
Upvotes: 0