How to display latitude and longitude for every five seconds using alarm manager in android? -
i creating application in have show reminder every 5 minutes. instead of reminder have show longitude , latitude every 5 minutes. have 2 activities: 1 alarmmanager
, other alarmmanagerbroadcastreceiver
. how do this?
public class alarmmanagerbroadcastreceiver extends broadcastreceiver { string gps; final public static string one_time = "onetime"; @override public void onreceive(context context, intent intent) { powermanager pm = (powermanager) context.getsystemservice(context.power_service); powermanager.wakelock wl = pm.newwakelock(powermanager.partial_wake_lock, "your tag"); wl.acquire(); bundle extras = intent.getextras(); stringbuilder msgstr = new stringbuilder(); if(extras != null && extras.getboolean(one_time, boolean.false)){ msgstr.append("reminder"); } format formatter = new simpledateformat("hh:mm:ss a"); msgstr.append(formatter.format(new date())); toast.maketext(context, "reminder", toast.length_long).show(); wl.release(); } public void setalarm(context context) { alarmmanager am=(alarmmanager)context.getsystemservice(context.alarm_service); intent intent = new intent(context, alarmmanagerbroadcastreceiver.class); intent.putextra(one_time, boolean.false); pendingintent pi = pendingintent.getbroadcast(context, 0, intent, 0); am.setrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis(), 1000 * 5 , pi); } public void cancelalarm(context context) { intent intent = new intent(context, alarmmanagerbroadcastreceiver.class); pendingintent sender = pendingintent.getbroadcast(context, 0, intent, 0); alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); alarmmanager.cancel(sender); } public void setonetime(context context){ alarmmanager am=(alarmmanager)context.getsystemservice(context.alarm_service); intent intent = new intent(context, alarmmanagerbroadcastreceiver.class); intent.putextra(one_time, boolean.true); pendingintent pi = pendingintent.getbroadcast(context, 0, intent, 0); am.set(alarmmanager
use method location on each 5 seconds
private final five_seconds = 5000; public void schedulesendlocation() { handler.postdelayed(new runnable() { public void run() { sendlocation(); // method contain almost-finished http calls handler.postdelayed(this, five_seconds); } }, five_seconds); }
Comments
Post a Comment