class="markdown_views prism-atom-one-light">
之前找过,关于电话的去电接通资料很少,把以前做过的项目中去电接通实现写一下,当时是去电接通后开始做计时处理:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//注册监听
mCM = CallManager.getInstance();
Phone phone = PhoneFactory.getDefaultPhone();
mCM.registerPhone(phone);
mCM.registerForPreciseCallStateChanged(mHandler, PHONE_STATE_CHANGED, null);
Log.e(TAG, "oncreat");
```
```
private CallManager mCM;
private static final int PHONE_STATE_CHANGED = 102;
private Button btton;
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case PHONE_STATE_CHANGED:
updatePhoneSateChange();
break;
}
}
};
```
```
private void updatePhoneSateChange() {
Call fgCall = mCM.getActiveFgCall();
if (mCM.hasActiveRingingCall()) {
fgCall = mCM.getFirstActiveRingingCall();
}
final Call.State state = fgCall.getState();
switch (state) {
case IDLE:
Log.e(TAG, "ISLE");
break;
case ACTIVE:
Log.e(TAG, "ACTIVE");//接通标志
break;
default:
break;
}
}
```
```