在Android中,当有来电时,我想要接收它。然后,在我的应用程序中,在通话过程中自动播放音频文件,对方应该会听到。这个是可能的吗?
发布于 2012-10-17 16:05:40
你正在谈论的事情在android上是不可能的。Android无法访问通话中的音频流。
不过,我可以给你一点关于如何做的想法。
首先,您需要注册一个广播接收器,该接收器在接收到呼叫时被调用
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>
这样,您就可以截取来电并挑选来电,现在您可以尝试在
case TelephonyManager.CALL_STATE_OFFHOOK:
// Play mp3 file here
break;
希望能有所帮助。一定要试一试,告诉我经验。
发布于 2012-10-17 16:08:37
您不能直接向调用者播放任何内容。如果你愿意,你可以通过扩音器播放,但这并不是你真正想要的。所以说“不”,你不能这么做。
https://stackoverflow.com/questions/12929489
复制相似问题