android - Send SMS only once from BroadcastReceiver -


i saw commonwares locationpoller demo here github.com/commonsguy/cwac-locpoll/

here in locationreceiver checking whether location in specified area or not. if not in area send text message(sms) phone number.

but sendind text messages(sms) continuously receives new location @ every specific interval. defined class varible flag=0 (initally)

            public class locationreceiver extends broadcastreceiver {                 int flag=0;             public void onreceive(context context, intent intent) {              ............               if( flag==0)    //center of campus                        {                           checkarea(loc,"500","22.599669","72.820473","5556","your ward out of college campus");                           toast.maketext(context, "you have moved out",toast.length_short);                           flag=1;                       }                 }             } 

but not working, still sends sms continuously. should ?

save unix timestamp when send message using sharedpreferences next time broadcast fired check existance of said timestamp. you'd send message if timestamp not exist or old enough (actual time - saved timestamp >= threshshold define), updating or creating timestamp when send message.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -