从Android应用程序到PHP服务器的GPS定期定位
如何从Android向服务器发送定期位置?我尝试了以下方法:从Android应用程序到PHP服务器的GPS定期定位,android,gps,alarm,Android,Gps,Alarm,如何从Android向服务器发送定期位置?我尝试了以下方法: Intent i = new Intent(this, UpdateLocation.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Repeat the notification ev
Intent i = new Intent(this, UpdateLocation.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
// Repeat the notification every 15 seconds (15000)
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * Interval, pi);
创建服务以将位置传递给服务器
public int-onstart命令(Intent-Intent、int-flags、int-startId){
super.onStartCommand(intent、flags、startId);
`
Starttimer函数
`私有void startTimer(){
//TODO自动生成的方法存根
// timer = new Timer();
// TimerTask myTask = new TimerTask();
Log.e("LOCATION SERVICE->out","THREAD IS RUN");
gps = new GpsTracker(SendLocationService.this);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Log.e("LOCATION",latitude+" "+longitude);
if(latitude!=0.0 && longitude!=0.0)
{
addressText = latitude+","+longitude;
// HERE YOU CAN PASS DATA TO SERVER
}
}
//
}
`
// timer = new Timer();
// TimerTask myTask = new TimerTask();
Log.e("LOCATION SERVICE->out","THREAD IS RUN");
gps = new GpsTracker(SendLocationService.this);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Log.e("LOCATION",latitude+" "+longitude);
if(latitude!=0.0 && longitude!=0.0)
{
addressText = latitude+","+longitude;
// HERE YOU CAN PASS DATA TO SERVER
}
}
//
}