Answer incoming call using android.telecom and InCallService
How do you get notified about, and acquire instances of GSM Calls
First, the user will need to select your app as the default Phone app. Refer to Replacing default Phone app on Android 6 and 7 with InCallService for a way to do that.
You also need to define an InCallService
implementation the system will bind to and notify you about the call:
<service
android:name=".CallService"
android:permission="android.permission.BIND_INCALL_SERVICE">
<meta-data
android:name="android.telecom.IN_CALL_SERVICE_UI"
android:value="true" />
<intent-filter>
<action android:name="android.telecom.InCallService" />
</intent-filter>
</service>
There you should handle at least onCallAdded
(set up listeners on Call
, start your UI - activity - for the call) and onCallRemoved
(remove listeners).
How does one answer these calls
If the user wants to answer the call, you need to invoke the method Call#answer(int)
with VideoProfile.STATE_AUDIO_ONLY
for example.
What is the life-cycle of the callbacks on this class
Check out Call.Callback
for events that can happen with a single call.
Does Google provide any actual tutorial for this that I haven't found
I don't know about Google, but you can check out my simplified example https://github.com/arekolek/simple-phone
Trying to redirect incoming call to custom made UI in android
User arekolek provided an answer to my question with his own source sample at the end.
I verified it working back when he posted it, and should still work on current Android versions. Hope that helps, I would suggest providing feedback to there if it does.
Replacing default Phone app on Android 6 and 7 with InCallService
The app compiles fine but Default Apps in settings doesn't show my app.
To have your app listed as a Phone app, you must have an activity with at least those intent filters (to handle both cases mentioned in documentation of ACTION_DIAL, also mentioned in DefaultDialerManager hidden class):
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
</intent-filter>
And to be honest, that's a bit counterintuitive, because setting the default Phone app is separate from setting a default Dialer – the former controls only the ongoing call UI, while the latter controls only the dialing UI.
The above minimum can be improved a bit, to allow setting your dialer as a default, and launching from web browser, by using these intent filters instead:
<intent-filter>
<!-- Handle links from other applications -->
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<!-- Populate the system chooser -->
<category android:name="android.intent.category.DEFAULT" />
<!-- Handle links in browsers -->
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
The Dialer app in AOSP has even more filters declared.
You can make it easier for the user to set your app as the default Phone app with the help from TelecomManager
:
if (getSystemService(TelecomManager::class.java).defaultDialerPackage != packageName) {
Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
.let(::startActivity)
}
This will show a dialog similar to this:
Refer to Answer incoming call using android.telecom and InCallService for what you need to do to actually handle the calls themselves.
Here's the code for an app that implements the minimum needed to handle dialing, and accepting/rejecting/ending calls in its own UI:
https://github.com/arekolek/simple-phone
Getting the direction is Incoming or Outgoing
If Call state is ringing :
if (call.getState() == Call.STATE_RINGING)
Its a incoming call
And if call state is connecting :
else if (call.getState() == Call.STATE_CONNECTING)
Its a outgoing call
Related Topics
How to Use the Paid Version of My App as a "Key" to the Free Version
Swiperefreshlayout Setrefreshing() Not Showing Indicator Initially
Creating a Softkeyboard with Multiple/Alternate Characters Per Key
Understanding Recyclerview Sethasfixedsize
Why Do I Want to Avoid Non-Default Constructors in Fragments
How to Center Icon and Text in a Android Button with Width Set to "Fill Parent"
How to Show an Empty View with a Recyclerview
Switching to Landscape Mode in Android Emulator
Android:Inapp Purchase Receipt Validation Google Play
How to Get Color-Int from Color Resource
Error: No Toolchains Found in the Ndk Toolchains Folder for Abi with Prefix: Llvm
Java.Lang.Noclassdeffounderror:Failed Resolution of :Lorg/Apache/Http/Protocolversion
Wrap_Content View Inside a Constraintlayout Stretches Outside the Screen
How to Export Library to Jar in Android Studio
How to Make Custom Dialog with Rounded Corners in Android
Why Was "Avoid Enums Where You Only Need Ints" Removed from Android's Performance Tips