我正在使用广播接收器接收 phone_states 并检查任何呼叫(呼出/呼入)正在更改其状态EXTRA_STATE_IDLE
,然后从通话记录中删除通话信息。据我所知,android手机状态是:
EXTRA_STATE_RINGING
EXTRA_STATE_OFFHOOK
EXTRA_STATE_IDLE
我知道来电:
- 接到来电时 ->
EXTRA_STATE_RINGING
=>EXTRA_STATE_OFFHOOK
(接听电话后)=>EXTRA_STATE_IDLE
(结束通话后) - 当来电被切断时 ->
EXTRA_STATE_RINGING
=>EXTRA_STATE_IDLE
(结束通话后)
所以,实际上我正在清除电话状态时的通话记录历史记录EXTRA_STATE_IDLE
。但在这个策略中,我能够清除 2. 场景的日志历史记录,但无法清除 1. 场景。
这是我的代码::
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
Toast.makeText(context, "ringing", 20).show();
SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);
SharedPreferences.Editor editor=statePreference.edit();
editor.putBoolean("State", true);
editor.commit();
context.startActivity(i);
}
else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Toast.makeText(context, "off hook", 20).show();
SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);
Log.d("statePref OFFHOOK", "state :: "+statePreference.getBoolean("State", false));
if(!statePreference.getBoolean("State", false)) {
SharedPreferences out_statePreference=context.getApplicationContext().getSharedPreferences("OutCallState", 0);
SharedPreferences.Editor out_editor=out_statePreference.edit();
out_editor.putBoolean("OutState", true);
out_editor.commit();
}
}
else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
Toast.makeText(context, "idle", 20).show();
SharedPreferences statePreference=context.getApplicationContext().getSharedPreferences("RingCallState", 0);
Log.d("statePref IDLE", "state :: "+statePreference.getBoolean("State", false));
if(statePreference.getBoolean("State", false))
{
SharedPreferences.Editor editor=statePreference.edit();
editor.putBoolean("State", false);
editor.commit();
Log.d("in", "in coming :: "+incomingNumber);
new Handler().postDelayed(new Runnable() {
public void run() {
clearLastCallLog(context, incomingNumber);
}
}, 4000);
}
SharedPreferences out_statePreference=context.getApplicationContext().getSharedPreferences("OutCallState", 0);
if(out_statePreference.getBoolean("OutState", false))
{
SharedPreferences.Editor out_editor=out_statePreference.edit();
out_editor.putBoolean("OutState", false);
out_editor.commit();
Log.d("out", "out going :: "+outgoingNumber);
new Handler().postDelayed(new Runnable() {
public void run() {
clearLastCallLog(context, outgoingNumber);
}
}, 4000);
}
}
我错过了什么......任何人都可以解释处理接听的来电有什么办法吗?有什么建议请...