我有实现位置监听器的服务。现在我的问题是如何确保我的服务即使在睡眠模式下也能捕获位置。我已阅读有关警报管理器的信息
alarm.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, operation);
但如何使用它。这是我的代码..任何帮助将不胜感激..
我的服务
public class LocationCaptureService extends Service implements LocationListener {
public static int inteval;
java.sql.Timestamp createdTime;
LocationManager LocationMngr;
@Override
public void onCreate() {
inteval=10*1000;
startLocationListener(inteval);
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
private void startLocationListener(int inteval,String nwProvider) {
this.LocationMngr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
this.LocationMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, inteval, 0, this);
}
public void onLocationChanged(Location location) {
String status="c",S=null;
double longitude,lattitude,altitude;
g_currentBestLocation = location;
createdTime = new Timestamp (new java.util.Date().getTime());
longitude=location.getLongitude();
lattitude=location.getLatitude();
altitude=location.getAltitude();
//use this
}
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
}