Is there a way to launch an audio file when answering a call to be played NOT into the call (so the other side could hear), but only in the call speaker (so only our side could hear).
Sounds strange, I know but it is part of a much larger app.
First of all, you'll need to set up a BroadcastReceiver (let's call it "CallReceiver"), and permission to know about the phone state (intuitively, the permission to add is android.permission.READ_PHONE_STATE
).
Register your CallReceiver action like this.
<receiver android:name=".CallReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
At your CallReceiver, you may decide upon which actions should your audio play back (incoming/outcoming/phone ringing...), so just read the EXTRA_STATE, and getCallState() (check out the TelephonyManager docs).
About the audio, you will need to use the AudioManager, and set the "in call" mode of playback before playing the sound.
private AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(false);
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With