【问题标题】:How to detect "call accepted" before "call died"?如何在“呼叫死亡”之前检测“呼叫已接受”?
【发布时间】:2013-03-12 14:58:04
【问题描述】:

我尝试为 android 编写一个程序。我想用我的程序拨打电话,然后识别通话状态。使用流动功能,我可以识别挂出状态,而对于应答状态,它不起作用。我尝试了这个功能,但它也不起作用。

我想在“呼叫终止”之前检测“呼叫已接受”。

public class OutgoingCallReceiver extends BroadcastReceiver {
    protected static final String CLASS_TAG = "OutgoingCallReceiver : ";
    private static final String LOG_TAG = "MyActivity";
    private ConnectivityManager connectivityManager;
    private TelephonyManager telephonyManager;
    private NetworkInfo networkInfo;
    private String networkStauts = "Not connected !!";



    //************************************
    @Override
    public void onReceive(Context context, Intent intent) {


        //Toast.makeText(getApplicationContext(),String.valueOf(isPhoneCalling), Toast.LENGTH_SHORT).show();
        Bundle bundle = intent.getExtras();
        if(null == bundle) return;          

        String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        //Log.i(LOG_TAG, CLASS_TAG + "phone number " + phonenumber);
        //Toast.makeText(getApplicationContext(),String.valueOf("phone number " + phonenumber), Toast.LENGTH_SHORT).show();
            tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

            tm.listen(new PhoneStateListener() {                    
                @Override
                public void onCallStateChanged(int state, String incomingNumber) {

                    switch (state) {
                    case TelephonyManager.CALL_STATE_RINGING:
                        Context context = getApplicationContext();
                        Toast.makeText(getApplicationContext(), "RINGING", Toast.LENGTH_SHORT).show();
                        break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:

                        Toast.makeText(getApplicationContext(), "OFFHOOK", Toast.LENGTH_SHORT).show();

                        isPhoneCalling = true;
                        break;
                    case TelephonyManager. CALL_STATE_IDLE:
                        if (isPhoneCalling) {
                            Toast.makeText(getApplicationContext(),
                                    "Your call is disconnected by receiver", 10000)
                                    .show();
                            Intent i = getBaseContext().getPackageManager()
                                    .getLaunchIntentForPackage(
                                             getBaseContext().getPackageName());
                             i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                             startActivity(i);

                             isPhoneCalling = false;
                             //duration=c.getLong(c.getColumnIndex(CallLog.Calls.DURATION));
                             Toast.makeText(getApplicationContext(), "IDLE", Toast.LENGTH_SHORT).show();
                            call();
                        }

                        break;
                    default:
                        Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
                        //Log.d(LOG_TAG, CLASS_TAG + "Default: " + state);
                        break;
                    }
                }

            }, PhoneStateListener.LISTEN_CALL_STATE )
            //registerReceiver(phoneInfo, new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL));
        }

}

【问题讨论】:

    标签: android broadcastreceiver call telephonymanager phone-state-listener


    【解决方案1】:

    这个问题没有解决办法。 Android 中没有 API 可以检测到成功发出的出站呼叫。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      相关资源
      最近更新 更多