I have an issue making phone calls from the foreground service and this is my question about that.
As suggested in the comments of the question - I started testing the ConnectionService. I added BIND_TELECOM_CONNECTION_SERVICE permission to the manifest file.
Declared MyConnectionService
class:
[Service(Permission= Manifest.Permission.BindTelecomConnectionService)]
public class MyConnectionService : ConnectionService
{
}
And then I run this code:
var telecomManager = (TelecomManager)GetSystemService(Context.TelecomService);
var phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(this.PackageName, nameof(MyConnectionService)), "MyApp");
var builder = new PhoneAccount.Builder(phoneAccountHandle, "CustomAccount");
var phoneAccount = builder.Build();
telecomManager.RegisterPhoneAccount(phoneAccount);
The telecomManager.RegisterPhoneAccount(phoneAccount);
gives me an exception:
Java.Lang.SecurityException: 'PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.'
Ok - it seems the permission is not granted. Testing it with ActivityCompat.CheckSelfPermission()
- yes, it is not granted.
Making a permission request with ActivityCompat.RequestPermissions()
- it is executed and that's it.
No permission request on the screen, not way to grant on the application permission page.
My question is - how to grant this kind of permission?
Environmet:
- Android API Level 28
- Testing on Google Pixel 2 XL phone running Android 10