android - How to block outgoing calls and texts to contacts (Prevent drunk dialing) -


i making android app class prevents users calling or texting while drunk. basically, before start drinking, start app block outgoing calls , texts contacts until answer math problem prove sobriety. i've hit snag while trying block calls , texts because can't seem broadcastreceivers accomplish this. when user hits "start" button, i'd broadcastreceiver start listening , blocking outgoing calls until user passes sobriety test (inputs correct answer math problem). there way accomplish this?

thanks ton! matt

here main activity:

public class mainactivity extends activity {      int answer;      /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          final edittext userinput = (edittext) findviewbyid(r.id.answerinput);         userinput.setenabled(false);          //this creates button object "start drinking" button         final button leftbutton = (button) findviewbyid(r.id.leftbutton);          //this creates button object "make call" button         final button rightbutton = (button) findviewbyid(r.id.rightbutton);         rightbutton.setenabled(false);          leftbutton.setonclicklistener(new view.onclicklistener() {             /**              * description: method listens click on "make call" button. once              * button clicked, method call other methods in order create               * random math problem, display problem user, , check see if user              * answered correctly. if did, method call dialer make              * phone call.              * @author matthew              * @params view object see button              * @return void              * @throws none              */             public void onclick(view v) {                 rightbutton.setenabled(true);                 leftbutton.setenabled(false);             }         });           rightbutton.setonclicklistener(new view.onclicklistener() {             /**              * description: method listens click on "send text" button. once              * button clicked, method call other methods in order create               * random math problem, display problem user, , check see if user              * answered correctly. if did, method call text messaging service              * allow user send text.               * @author matthew              * @params view object see button              * @return void              * @throws none              */             public void onclick(view v) {                 answer = createmathproblem();                 userinput.setenabled(true);             }         });          userinput.setonkeylistener(new onkeylistener() {              public boolean onkey(view v, int keycode, keyevent event) {                 string text = userinput.gettext().tostring();                 // if event key-down event on "enter" button                 if ((event.getaction() == keyevent.action_down)                         && (keycode == keyevent.keycode_enter)) {                     if (matchanswer(answer, integer.parseint(text))) {                         leftbutton.setenabled(true);                         rightbutton.setenabled(false);                         userinput.setenabled(false);                         //airplane();                         toast.maketext(mainactivity.this, "correct!", toast.length_long).show();                     }                     return true;                 }                 return false;             }         });      }      /**      * description: method checks see if user answered math problem      * correctly.      * @author matthew      * @params correct answer math problem , user's input answer      * @return true or false depending on if user answered correctly      * @throws none      */     public boolean matchanswer(int correctanswer, int useranswer) {         return (correctanswer == useranswer);     }      /**      * description: method creates random math problem user       * answer , displays screen.       * @author matthew      * @params none      * @return correct answer math problem.      * @throws none      */     public int createmathproblem() {         int random1 = (int) (math.random() * 100);         int random2 = (int) (math.random() * 100);         int answer = random1 + random2;         toast.maketext(mainactivity.this, random1 + " + " + random2 + " = ?", toast.length_long).show();         return answer;     }   } 

here broadcastreceiver:

public class calltextreceiver extends broadcastreceiver {      public void onreceive(context context, intent intent) {         if (intent.getaction().equals(intent.action_new_outgoing_call)) {             if (getresultdata() != null) {                 setresultdata(null);                  toast.maketext(context, "blocked", toast.length_long).show();             }         }     } } 

since cyanogenmod open source, might able find out answer looking through phone goggles code: http://www.cyanogenmod.com/features/phone-goggles

since accomplishes same thing trying write separate app, nice people not running cm7.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -