The example of this article is about the implementation of the Android monitor caller and power off. Share to everyone for your reference, specific as follows:
To monitor the Android phone and answer the phone, just the following 2 steps
The first step is to write a receiver inherited from Broadcastreceiver
Import Android.app.Service;
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.telephony.TelephonyManager;
Import Android.util.Log; public class Phonestatebroadcastreceiver extends Broadcastreceiver {private static final String TAG = "PHONESTATEBROADCA
Streceiver ";
private static Boolean mincomingflag = false;
private static String mincomingnumber = null; @Override public void OnReceive (context context, Intent Intent) {//If the call is (Intent.getaction (). Equals (Intent.acti
On_new_outgoing_call)) {Mincomingflag = false;
String PhoneNumber = Intent.getstringextra (Intent.extra_phone_number);
LOG.I (TAG, "call out:" + PhoneNumber); else {//if the caller telephonymanager Tmanager = (telephonymanager) context.getsystemservice (service.telephony_service
); Switch (tmanager.getcallstate ()) {Case TelephonyManager.CALL_STATE_RINGING:mIncomingNumber = Intent.getstringextra
("Incoming_number"); LOG.I (TAG, "ringing:" + mincomingnumber);
Break
Case TelephonyManager.CALL_STATE_OFFHOOK:if (Mincomingflag) {log.i (TAG, "Incoming ACCEPT:" + mincomingnumber);
} break;
Case TelephonyManager.CALL_STATE_IDLE:if (Mincomingflag) {log.i (TAG, "incoming IDLE");
} break;
}
}
}
}
Step two: In Androidmanifest.xml, configure the written receiver, and intercept the corresponding broadcastaction,
Also note that the appropriate permissions are added
<receiver android:name= ". Broadcase. Phonestatebroadcastreceiver ">
<intent-filter>
<action android:name=" Android.intent.action.PHONE_STATE "/>
<action android:name=" Android.intent.action.NEW_OUTGOING_CALL " >
</intent-filter>
</receiver>
<uses-permission android:name= " Android.permission.READ_PHONE_STATE "/>
<uses-permission android:name=" android.permission.PROCESS_ Outgoing_calls "/>
PS: Here again to provide you with a Androidmanifest.xml access control online query tool:
Android manifest Features and Permissions description Encyclopedia:
Http://tools.jb51.net/table/AndroidManifest
More interested readers of Android content can view this site: "Android SMS and phone Operation tips Summary", "Android operation SQLite Database Skills Summary", "Android Development introduction and Advanced Course", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.