2

我想更改特定号码的响铃模式。例如我保存了一个号码

String Number = "12345567"

现在在来电时,它会检查

if(incoming_cal-_no == Number)
{
   ring_mode = silent
}

我想做这样的事情???我怎样才能做到这一点????

4

1 回答 1

0

创建用于收听来电的广播接收器

当您收到任何来电时,解析呼叫信息并获取电话号码

像这样的东西

公共类电话扩展广播接收器{

private Context mContext;
private Intent mIntent;

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;
    mIntent = intent;
    TelephonyManager tm = (TelephonyManager)              
             context.getSystemService(Context.TELEPHONY_SERVICE);
    int events = PhoneStateListener.LISTEN_CALL_STATE;
    tm.listen(phoneStateListener, events);
}

private final PhoneStateListener phoneStateListener = 
                                            new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        String callState = "UNKNOWN";
        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:

            break;
        case TelephonyManager.CALL_STATE_RINGING:
                            // DO YOUR WORK HERE

                 put logic to silent the phone.

            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
                      if(incomingNumber.length() >0){


                              // incoming call
                             // DO YOUR WORK HERE when call is received





                        }
                       else{
                                  // outgoing call
                          }
            break;
        }

        super.onCallStateChanged(state, incomingNumber);
    }
};

}

于 2012-12-06T15:23:10.017 回答