That's what I trying to do in the background, but nothing happens. I'm using push notifications(Firebase Messaging Service) to run this code.
phoneAccountHandle = PhoneAccountHandle(
ComponentName(
packageName,
DoctorConnectionService::class.java.name
), phoneAccountHandleId
)
val builder = PhoneAccount.builder(phoneAccountHandle, "My account")
builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER or PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
val phoneAccount = builder.build()
val test = telecomManager
telecomManager?.registerPhoneAccount(phoneAccount)
telecomManager?.addNewIncomingCall(phoneAccountHandle, Bundle())
You can try BroadcastReceiver. Here is my BroadcastReceiver's Class & MainActivity. In here I just Toast a message (Incoming Call) when application is in background:
MainActivity:
And here is my BroadcastReceiver class:
Then Add
READ_PHONE_STATE
Permission in Manifest and add BroadcastReceiver's class in Manifest, Inside Application Tag: