Here is the main summary of how to monitor the problem of missed calls
1.1 using broadcast receivers Brocastreceiver
Realize the idea:
Static registration listens for Android.intent.action.PHONE_STATE broadcast receivers will trigger onreceive when the status of the phone changes.
The status of the mobile phone is divided into call_state_ringing (Bell), Call_state_idle (Idle), Call_state_offhook (busy tone).
In other words, when you do not have any phone is, the state is IDLE, when the phone is Offhook, the phone after the end of the return to the IDLE state.
Record the last time the mobile phone status, if the phone is now idle, the last state of the bell, you can judge is missed calls.
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<receiver android:name= " Com.example.phonestatedemo.receiver.PhoneStateReceiver ">
<intent-filter >
<action android: Name= "Android.intent.action.PHONE_STATE"/>
</intent-filter>
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.telephony.TelephonyManager;
Import Android.util.Log;
Import Android.widget.Toast; public class Phonestatereceiver extends Broadcastreceiver {private static int lastcallstate = Telephonymanager.call_
State_idle;
@Override public void OnReceive (context arg0, Intent arg1) {String action = arg1.getaction ();
LOG.D ("Phonestatereceiver", action);
Telephonymanager Telephonymanager = (telephonymanager) arg0. Getsystemservice (Context.telephony_service);
int currentcallstate = Telephonymanager.getcallstate ();
LOG.D ("Phonestatereceiver", "currentcallstate=" + currentcallstate); if (currentcallstate = = Telephonymanager.call_state_idle) {//idle//todo} else if (currentcallstate = = Teleph onymanager.call_state_ringing) {//Bell//todo} else if (currentcallstate = = telephonymanager.call_state_ofFhook) {//Answering//todo} if (lastcallstate = = Telephonymanager.call_state_ringing && cu
Rrentcallstate = = Telephonymanager.call_state_idle) {toast.maketext (arg0, "missed calls", 1). Show ();
} lastcallstate = Currentcallstate;
}
}
1.2 uses the Phonestatelistener
Implementation idea: After
Inherits Phonestatelistener, When the phone's state changes, it triggers oncallstatechanged. The status of the mobile phone is divided into call_state_ringing (Bell), Call_state_idle (Idle), Call_state_offhook (Busy signal).
that is, when you do not have any phone number, the status is IDLE, when the phone is Offhook, return to the IDLE state after the phone is over.
Record the last time the mobile phone status, if the phone is now idle, the last state of the bell, you can be judged to have missed the call.
&NBSP
is not sufficient: the current processing does not determine whether the user actively does not answer the phone.
Telephonymanager Telephonymanager = (Telephonymanager) this. Getsystemservice (Context.telephony_service);
Telephonymanager.listen (The new Callstatelistener (this), phonestatelistener.listen_call_state);
Package Com.example.phonestatedemo.listener;
Import Android.content.Context;
Import Android.telephony.PhoneStateListener;
Import Android.telephony.TelephonyManager;
Import Android.util.Log;
Import Android.widget.Toast; public class Callstatelistener extends Phonestatelistener {private static int lastetstate = Telephonymanager.call_stat E_idle;
The final state is private context;
Public Callstatelistener {this.context = context; @Override public void oncallstatechanged (int state, String incomingnumber) {//TODO auto-generated method
Stub super.oncallstatechanged (state, Incomingnumber);
LOG.D ("Callstatelistener", "oncallstatechanged state=" + state);
If the current state is idle and the last status is a bell, the GU is considered to be a missed call if (lastetstate = = telephonymanager.call_state_ringing && state = = Telephonymanager.call_state_idle) {
TODO Toast.maketext (This.context, "Callstatelistener has missed calls", 1). Show ();
} lastetstate = State;
}
}