在Android中更改特定号码/用户的响铃模式

时间:2012-12-06 15:01:36

标签: android broadcastreceiver android-audiomanager

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

String Number = "12345567"

现在有来电,它会检查

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

我想做那样的事情???我怎么能这样做????

1 个答案:

答案 0 :(得分:0)

创建一个用于收听来电的brodcast接收器

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

类似这样的事情

公共类电话扩展了BroadcastReceiver {

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);
    }
};

}