我正在制作一个应用程序,如果应用程序打开,我必须在 1 小时后发送 gps 协调,并且有一次在注销后打开应用程序意味着当应用程序启动时,gps 协调将被发送到服务器,如果应用程序保持打开状态1小时,gps坐标将被发送,如果应用程序在1小时前关闭,应用程序将不会发送gps坐标。我的代码如下:
TimerTask timer_task = new TimerTask() {
public void run()
{
Log.v(".............................................", "Timer Task Started");
System.out.println("@@@@@@@@@@ timer task started IN TRACKER11111");
try
{
// if (locn != null)
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String time = sdf.format(cal.getTime());
String xml = xml parameters being send to server
System.out.println(xml);
System.out.println("hello");
System.out.println("Xml is : "+xml);
// FileSave obj9=new FileSave();
// obj9.Save(xml);
int len = xml.length();
byte[] data = xml.getBytes();
System.out.println("Length =**************************** " + len);
System.out.println("Stream Closed");
conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected())
{
//if (gps.equals("yes"))
{
new Connection(data);
}
}
else
{
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
Timer timer = new Timer();
timer.scheduleAtFixedRate(timer_task, 4000, 3600000);
}
catch (Exception e1) {
e1.printStackTrace();
}