android - Press Power button Twice to send SMS -


i have written app in user can send messages whenever press button given in activity, , works fine me, target send sms using double press on power button.

but don't have idea, how ?

   send sms using double press on power button 

below code, using send sms:

 btnpanic.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             string message = "my current location is:" + "\t" + currentlocation ;              string phoneno = editcontacts.gettext().tostring();              stringtokenizer st=new stringtokenizer(phoneno,",");             while (st.hasmoreelements())             {                 string tempmobilenumber = (string)st.nextelement();                 if(tempmobilenumber.length()>0 && message.trim().length()>0) {                     sendsms(tempmobilenumber, message);             }             else              {               toast.maketext(getbasecontext(),                  "please enter both phone number , message.",                   toast.length_short).show();             }         }     } }); 

i can give idea how can implement it's hardcoded.

pardon me if went wrong.!!

this kind of conversion of key event double click.

so here i considering key pressed twice double click

first see key event of power button.

1

@override public boolean onkeydown(int keycode, keyevent event) {     if(keyevent.keycode_power == event.getkeycode()){       if(time interval less)//consider double click        //code send messages         else            //consider single click        //nothing        }     return super.onkeydown(keycode, event); } 

2. should use system.currenttimemillis() find time of 2 clicks in double click can validated.

try doubleclick , record time , many times precise time.

so in short have first find how maximum time allowed beetween 2 click considered doubleclick.

so can differentiate beetween click , doubleclick.

3 @ key event need this

long l=0;//at start not in key event handler  if(l=0){l=system.currenttimemillis();}//clicked first time else{l=system.currenttimemillis()-l;}//second time 

and done use long values decide click or double click.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -