First, the goal
Using broadcastreceive to obtain the power-off broadcast, and obtain the power-off number, and then query the database to obtain attribution information;
Second, the code implementation:
1, in the broadcast packet (receiver) under a new class (named Outcallreceiver) inherit broadcastreceive;
2, register in the manifest file, Intent Filter (Inter-filter) to listen for the action is to power off (New_outgoing_call)
Broadcast Recipient Registration Code:
1 <receiver android:name= "Com.example.mobilesafe.receiver.OutCallReceiver" >2 < Intent-filter >3 <action android:name= "Android.intent.action.NEW_OUTGOING_CALL"/>4 </intent-filter>5 </receiver>
View Code
3, increase the power of monitoring to access (Process_outgoing_calls)
4, in 1 new Class (Outcallreceiver), through the Getresultdata () method to obtain a string type of the power-down number (named Outcallnumb);
5, through the Custom Number Attribution Query Tool Class (Numberaddqueryutils) in the Query method Querynumber (String number) in 4 to pass the numbers obtained in, returns the String type of attribution information, Finally, it can be displayed by toast.
New Class (Outcallreceiver) code:
1 Public classOutcallreceiverextendsBroadcastreceiver {2 3 @Override4 Public voidOnReceive (Context context, Intent Intent) {5 //get the Power off number6String Outcallnumb =Getresultdata ();7 //Querying the database8String Outcalladd =Numberaddqueryutils.querynumber (outcallnumb);9Toast.maketext (Context, Outcalladd, 1). Show ();Ten } One}View Code
Android instance-Mobile security Defender (37)-shows the attribution of the power-off number