Android phone blocker

Source: Internet
Author: User

1. bedstead aidl file, itelephony.aidl This file is created under the Aidl folder under the Com.android.internal.telephony package

2. itelephony file add interface and method, so that you write this file and only add these two methods, you do not have to introduce cellinfo.aidl such a file (note: The content of this file can use the content provided by Google, there are many other interfaces, I don't know what the difference is between this customization and the use of the file provided by Google.

 Package com.android.internal.telephony;     Interface  itelephony{        boolean  endcall (); This is the void Answerringingcall () that is        later used to be called to end the call   ;    }

3. A service to dynamically turn on a listening phone broadcast

3.1 Broadcast class for listening

 Public classBlacklistphonereceiverextendsBroadcastreceiver {PrivateTelephonymanager TM; @Override Public voidOnReceive (Context context, Intent Intent) {//Get the blacklist data and compare it to the recipient.Jxblacklistdao DAO =NewJxblacklistdao (context); List<BlackListContact> blacklistcontacts =Dao.queryall (); TM=(Telephonymanager) Context.getsystemservice (Service.telephony_service); //Monitor the status of the phone, that is, whether there is a call incoming        Switch(Tm.getcallstate ()) { CaseTelephonymanager.call_state_ringing://start BellString Incomingnum =Intent.getstringextra (Telephonymanager.extra_incoming_number); Get the number of the call//This call number and the blacklist in the comparison (here is the blacklist database inside the phone, this library is created and add a number), if the number and the blacklist of the same number then hang up the phone and delete his call record, here the way to delete the call record is the simplest                  for(Blacklistcontact contact:blacklistcontacts) {if(Contact.getphone (). Equals (Incomingnum)&& (contact.gettype () = =BlackListContact.BlackType.ALL|| Contact.gettype () = =BlackListContact.BlackType.PHONE)) {Endcall (); Systemclock.sleep (1000); //Delete Call HistoryContentresolver resolver =Context.getcontentresolver (); Uri URI= Uri.parse ("Content://call_log/calls"); Resolver.delete (URI,"Number=?",Newstring[]{incomingnum}); }} toast.maketext (Context,"Incoming call is" +Incomingnum, Toast.length_short). Show ();  Break; }    }    //Hang up the phone    Private voidEndcall () {LOG.E ("John", "Blacklistreceiver" + "#" + "End Call method Running"); Class<TelephonyManager> CLZ = Telephonymanager.class; Try{Method Getitelephony= Clz.getdeclaredmethod ("Getitelephony",NULL); Getitelephony.setaccessible (true); Itelephony Itelephony=NULL; LOG.E ("John", "Blacklistreceiver" + "#" + "End Call"); Itelephony= (itelephony) Getitelephony.invoke (TM,NULL);        Itelephony.endcall (); } Catch(nosuchmethodexception e) {e.printstacktrace (); } Catch(InvocationTargetException e) {e.printstacktrace (); } Catch(illegalaccessexception e) {e.printstacktrace (); } Catch(RemoteException e) {LOG.E ("John", "Blacklistreceiver" + "#" + "Endcall Error");        E.printstacktrace (); }    }}

3.2 Service class for registered broadcast

 Public classBlacklistserviceextendsService {

PrivateBlacklistphonereceiver Phonereceiver; @Nullable @Override Publicibinder onbind (Intent Intent) {return NULL; } @Override Public voidonCreate () {//Radio registration for telephone monitoringPhonereceiver =NewBlacklistphonereceiver (); Intentfilter Filter2=NewIntentfilter (); Filter2.addaction ("Android.intent.action.NEW_OUTGOING_CALL"); Filter2.addaction ("Android.intent.action.PHONE_STATE"); Filter.setpriority (Integer.max_value); Registerreceiver (Phonereceiver, Filter2); //Register a broadcast} @Override Public voidOnDestroy () {Super. OnDestroy (); //Close ServiceMsgreceiver =NULL; Phonereceiver=NULL; }}

4. Add a button to the page, when the service is turned on the dynamic registration to open the interception of the call radio

Android phone blocker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.