Why it is not possible to play an audio file on a voice call in android
After a thorough research, what I have come to know is that there are more than one limitations/hurdles to make it possible. These limitations/hurdles are at three different levels.
First limitation is at API level, because there is no high-level API to play sound files in the conversation audio during a call as mentioned in Android official documentation.
Second limitation is at Radio Interface Layer (RIL). RIL passes on complete control of the call to Radio Daemon (rild) of the Linux library which then further passes the control to the vendor RIL. That means we cannot manipulate voice call in android source code.
Even if we are able to remove these two limitations, we may still not be able to play audio file to an ongoing voice call. Because there is a third limitation. Every vendor has their own library of RIL that communicates with Radio Daemon (rild). This requires that vendor RIL to be open source which is not actually. Hardware vendors do not usually make their device drivers code available.
Detail discussion on this topic is present at this link.
How to play audio file when call starts?
I have found a workaround with this. I play an audio file on device's speakers with full sound when the phone state changes to TelephonyManager.CALL_STATE_OFFHOOK
This ensures that the user on the other side can hear the recording.
Related Topics
How to Run Android Studio (Android Sdk Emulator) in a Microsoft Hyper-V Virtual Machine
Glide Showing Error: Failed to Find Generatedappglidemodule
Evenly Spaced Menu Items on Toolbar
Animation for Expandablelistview
Using Espresso to Unit Test Google Maps
How to Get Current Process Name in Android
Does Android Service Run from a Separated Thread Instead of UI
Service Intent Must Be Explicit: Intent
Using Onbackpressed() in Android Fragments
Onoptionsitemselected Not Called When Using Actionlayout (Sherlockactionbar)
How to Capture Key Events from Bluetooth Headset with Android
Failed to Find Build Tools Revision 21.1.1 - Sdk Up to Date
Setting Action Bar Title and Subtitle
Just Upgraded My Os X to Yosemite, Android Device Chooser Not Showing Device - What to Do