我是想得到呼叫被接起时的事件。我搜索了一下,发现应该使用CALL_STATE_OFFHOOK。但是这并不奏效。这个状态在号码被拨通时就会被调用。这是我的代码。
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
// But this gets called as soon as number is dialled.
endCall();
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
phoneCalling = true;
new CountDownTimer(MyApplication.GetData().getDuration()*1000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
endCall();
}
}.start();
}
// When the call ends launch the main activity again
if (TelephonyManager.CALL_STATE_IDLE == state) {
MyApplication.GetData().setIsReturnedFromCall(false);
if (phoneCalling) {
phoneCalling = false;
}
}
我发现这是由于我的 call recorder
应用 uninstalling
和 reinstalling
毫无区别。我不得不进入设置,然后是应用程序,点击应用程序,和存储,其次是 clear data
. 这就解决了这个问题。