【问题标题】:Is there any way to know if an outgoing call is accepted?有没有办法知道拨出电话是否被接受?
【发布时间】:2012-07-26 11:34:37
【问题描述】:

我正在做一个记录通话的应用程序(包括来电和去电)。

我刚刚解决了来电录音的问题,但我发现拨出电话有些问题。

接下来是我的情况。我只想在接听电话时录制音频,但我不知道该怎么做。我刚刚尝试过使用 PhoneStateListener 类,但是在接受呼叫时呼叫状态不会改变。我有下一个代码:

package com.call.record.listeners;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class OutgoingPhoneStateListener extends PhoneStateListener{

    private String phoneNumber;

    public OutgoingPhoneStateListener(String pn) {
        // TODO Auto-generated constructor stub
        super();
        phoneNumber = pn;
    }

    public void onCallStateChanged(int state, String incomingNumber){

        switch(state){
            case TelephonyManager.CALL_STATE_IDLE:
              Log.d("DEBUG", "IDLE");
            break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
              Log.d("DEBUG", "OFFHOOK");
            break;
            case TelephonyManager.CALL_STATE_RINGING:
              Log.d("DEBUG", "RINGING");
            break;
        }
    }
}

在前面的代码中,当呼叫拨出时

【问题讨论】:

    标签: android call audio-recording phone-state-listener


    【解决方案1】:

    我认为没有任何非骇客/稳健的方法可以找出对方何时接听电话。 CALL_STATE_OFFHOOKMODE_IN_CALL (AudioManager) 都将在拨打电话后立即设置,而不是在对方接听时设置。

    您可以做的是即时处理记录的下行链路数据,以尝试检测何时接听电话。希望对方会回答某种问候语,您可以尝试通过分析音频数据来确定对话何时开始来检测这些问候语。或者您可以查看上行链路并将您对着麦克风说的第一个词用作对话已经开始的信号(因为您不太可能在对方回答之前开始说话)。

    【讨论】:

      【解决方案2】:

      我完全同意 Michael 的观点,没有可靠的方法可以确定 android 中的 calle 何时应答了呼叫。即电话管理器。 CALL_STATE_OFFHOOK会在您拨打电话后立即设置。

      试试这个例子你就明白了

      public class BroadcastReceiverImpl extends BroadcastReceiver{
      
          @Override
          public void onReceive(Context context, Intent intent) {
      
              Toast.makeText(context, "Monitoring The Network !! ", Toast.LENGTH_LONG).show();
              PhoneStateListnerImpl phoneStateListnerImpl = new PhoneStateListnerImpl(context);
              TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
      
                  telephonyManager.listen(phoneStateListnerImpl, PhoneStateListener.LISTEN_CALL_STATE);
      
      
              }
      
          private class PhoneStateListnerImpl extends PhoneStateListener{
      
              private Context mContext;
      
              public PhoneStateListnerImpl(Context mContext) {
                  this.mContext = mContext;
              }
      
      
              @Override
              public void onCallStateChanged(int state, String incomingNumber) {
      
                  switch (state) {
      
                  case TelephonyManager.CALL_STATE_RINGING:
                       Toast.makeText(mContext, "Phone is Ringng ", Toast.LENGTH_LONG).show();
      
                      break;
      
                  case TelephonyManager.CALL_STATE_OFFHOOK:
                       Toast.makeText(mContext, "Phone is Answered ", Toast.LENGTH_LONG).show();
      
                      break;
      
                  case TelephonyManager.CALL_STATE_IDLE:
                       Toast.makeText(mContext, "Call Is Over ", Toast.LENGTH_LONG).show();
      
                       abortBroadcast();
                      break;
      
                  default:
                      break;
                  }
              }
      
          }
      }
      
      manifest :
      
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.pervazive.monitor_network_v08"
          android:versionCode="1"
          android:versionName="1.0" >
      
          <uses-sdk
              android:minSdkVersion="8"
              android:targetSdkVersion="16" />
      
          <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
          <uses-permission android:name="android.permission.READ_PHONE_STATE" />
          <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
          <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
      
          <application
              android:allowBackup="true"
              android:icon="@drawable/ic_launcher"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" >
              <receiver
                  android:name="com.example.broadcastreceiver.BroadcastReceiverImpl"
                  android:enabled="true"
                  android:exported="true" >
                  <intent-filter>
                      <action android:name="android.intent.action.ACTION_PHONE_STATE_CHANGED" />
                      <action android:name="android.intent.action.ACTION_NEW_OUTGOING_CALL" />
                      <action android:name="android.intent.action.PHONE_STATE" />
                      <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                  </intent-filter>
              </receiver>
          </application>
      
      </manifest>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-07
        • 2014-06-14
        • 2020-01-15
        • 1970-01-01
        • 2014-11-13
        • 2013-05-25
        • 1970-01-01
        • 2023-03-18
        相关资源
        最近更新 更多