接听电话时触发音频文件
有没有办法在接听电话时启动音频文件,而不是在通话中播放(以便另一方可以听到),而仅在通话扬声器中播放(以便只有我们这边可以听到)。
听起来很奇怪,我知道,但它是一个更大的应用程序的一部分。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要设置一个 BroadcastReceiver (让我们称之为“CallReceiver”),以及了解手机状态的权限(直观上,添加的权限是
android.permission.READ_PHONE_STATE
)。像这样注册您的 CallReceiver 操作。
在 CallReceiver 处,您可以决定音频播放的操作(传入/传出/电话铃声...),因此只需阅读 EXTRA_STATE 和 getCallState()(查看 TelephonyManager 文档)。
关于音频,您需要使用 AudioManager,并设置“通话中”播放模式之前播放声音。
我希望这有帮助!
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.
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.
I hope this helps!