通过android BroadcastReceiver传出呼叫信息

时间:2011-11-22 12:59:21

标签: android phone-call outgoing-call

我想在拨打号码后找到一些事件,即在目的地,呼叫被接受或拒绝或忙或不可达。如何在android中找到这些事件。我在android.TelephonyManager中找到了一些API,但是在IN_COMMING_CALL中找到了一些API。我在拨打号码后使用BroadcastReceiver()查找事件。这段代码是,

public void onReceive(Context context, Intent intent) {
    System.out.println("before if condition");
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            System.out.println("**outgoingcall***");
        }       
};

我无法在目的地设备上找到接听或拒绝或忙碌的电话。是否有任何基于网络的API在android中的outgoing_call期间找到这些事件?请帮帮我

我也使用了PhoneStateListener,代码是

private class ListenToPhoneState extends PhoneStateListener {

    public void onCallStateChanged(int state, String incomingNumber) {
        Log.i("telephony-example", "State changed: " + stateName(state));
    }

    String stateName(int state) {
        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE: 
            System.out.println("phone is idle****");
            break;  
            case TelephonyManager.CALL_STATE_OFFHOOK: 
            System.out.println("phone is offhook****");
            break;  
            case TelephonyManager.CALL_STATE_RINGING:
            System.out.println("phone is Ringing***");
            break;  
        }
        return Integer.toString(state);
    }
}

但我没有收到Outgoing_call上的活动.. 谢谢 希夫

1 个答案:

答案 0 :(得分:0)

使用PhoneStateListener或关注ACTION_PHONE_STATE_CHANGED广播意图。