java - Blocking incoming call in android 6.0 -


i use permission in manifest.xml (call_phone,read_phone_state,process_incoming_calls,modify_phone_state) ,itelephony.aids show code in blog . in itelephony.aids write want disable incoming call when checkbox checked . code not return error not work . test in android 6.0 . please me

checkbox blockall_cb;//,blockcontacts_cb; broadcastreceiver callblocker; telephonymanager telephonymanager; itelephony telephonyservice;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_my_call_controller);       initviews();     blockall_cb.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {          @override         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {             log.d("error 8","is checked1");             // todo auto-generated method stub             callblocker =new broadcastreceiver()             {                 @override                 public void onreceive(context context, intent intent) {                     log.d("error 8","is checked2");                     // todo auto-generated method stub                     telephonymanager = (telephonymanager)context.getsystemservice(context.telephony_service);                     //java reflections                     class c = null;                     try {                         c = class.forname(telephonymanager.getclass().getname());                     } catch (classnotfoundexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                         log.d("error 1",""+e);                     }                     method m = null;                     try {                         m = c.getdeclaredmethod("getitelephony");                     } catch (securityexception e) {                         // todo auto-generated catch block                         log.d("error 2",""+e);                         e.printstacktrace();                     } catch (nosuchmethodexception e) {                         // todo auto-generated catch block                         log.d("error 3",""+e);                         e.printstacktrace();                     }                     m.setaccessible(true);                     try {                         telephonyservice = (itelephony)m.invoke(telephonymanager);                     } catch (illegalargumentexception e) {                         log.d("error 4",""+e);                         // todo auto-generated catch block                         e.printstacktrace();                     } catch (illegalaccessexception e) {                         log.d("error 5",""+e);                         // todo auto-generated catch block                         e.printstacktrace();                     } catch (invocationtargetexception e) {                         log.d("error 6",""+e);                         // todo auto-generated catch block                         e.printstacktrace();                     }                     telephonymanager.listen(callblocklistener, phonestatelistener.listen_call_state);                 }//onreceive()                 phonestatelistener callblocklistener = new phonestatelistener()                 {                     public void oncallstatechanged(int state, string incomingnumber)                     {                         if(state==telephonymanager.call_state_ringing)                         {                             if(blockall_cb.ischecked())                             {                                 try {                                     telephonyservice.endcall();                                     log.d("error end","endcall");                                 } catch (remoteexception e) {                                     log.d("error 7",""+e);                                     // todo auto-generated catch block                                     e.printstacktrace();                                 }                             }                         }                     }                 };             };//broadcastreceiver             intentfilter filter= new intentfilter("android.intent.action.phone_state");             registerreceiver(callblocker, filter);         }     }); } public void initviews() {     blockall_cb=(checkbox)findviewbyid(r.id.cbblockall);     //blockcontacts_cb=(checkbox)findviewbyid(r.id.cbblockcontacts); } @override protected void ondestroy() {     log.d("error 8","error 8");     // todo auto-generated method stub     super.ondestroy();  } } 


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -