触发音频文件时,呼叫被应答 [英] Trigger an audio file when call is answered

查看:190
本文介绍了触发音频文件时,呼叫被应答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法回答的时候调用不播放到电话(以便对方能听到),但只有在通话扬声器(所以只有我们这边能听到)合作推出的音频文件。

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.

推荐答案

首先,你需要建立一个的 BroadcastReceiver的(姑且称之为CallReceiver),并允许以了解手机状态(直观,添加的权限是 android.permission。 READ_PHONE_STATE )。

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).

这样注册您的CallReceiver行动。

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>

在你CallReceiver,你可以决定哪些行为应该音频播放(呼入/ outcoming /电话铃声......),所以只是看了EXTRA_STATE和getCallState()(检查出的 TelephonyManager 文档)

有关音频,您需要使用 AudioManager ,和播放声音之前设置呼叫模式播放。

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!

这篇关于触发音频文件时,呼叫被应答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆