Android:来电自动接听,播放音频文件 [英] Android: Incoming call auto answer, play a audio file
问题描述
在Android中,我想接听电话.然后,通过我的应用程序,在通话过程中自动播放音频文件,另一方应听到该文件.这可能吗?
In Android, at the time of an incoming call, I want to receive it. Then, from my app, automatically play an audio file during a call and the other party should hear it. Is this possible?
推荐答案
您正在谈论的内容并非完全可以通过android实现. Android无法访问通话中的音频流.
What you are talking about is not exactly possible with android. Android has no access to the in-call audio stream.
尽管我可以给您一些有关如何做的想法.
Though i can give you a little bit idea about how to do it.
首先要拦截呼入电话,您需要注册一个广播接收器,每当接收到呼叫时都会调用该接收器
first to intercept incoming call, you need to register a broadcast receiver, which is invoked whenever call is received
public void onReceive(final Context context, Intent intent)
{
TelephonyManager telephonyManager = null;
PhoneStateListener listener = new PhoneStateListener()
{
public void onCallStateChanged(int state, String incomingNumber)
{
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(context, "Call Ended..", Toast.LENGTH_LONG).show();
Log.i("stop", "Call Ended....");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(context, "Call Picked..", Toast.LENGTH_LONG) .show();
Log.i("received", "Call Picked....");
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(context, "Call Ringing.." + incomingNumber,5000).show();
break;
}
}
};
// Register the listener with the telephony manager
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
还要更改您的清单,
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="MyReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
有了这个,您可以截获来电并接听电话,现在您可以尝试在
With this, you can intercept the incoming call and pick the call, now you can try playing some mp3 file in the
case TelephonyManager.CALL_STATE_OFFHOOK:
// Play mp3 file here
break;
希望它会有所帮助.必须尝试一下并告诉我经验.
Hope it helps. Must try this and tell me the experience.
这篇关于Android:来电自动接听,播放音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!