GPS状态的自动监测

超过10分钟,自动关闭
TempBranch
Matthew 9 months ago
parent 72f595b7a3
commit 8dab92b04d

@ -137,6 +137,7 @@ public class MicroPhotoService extends Service {
private long mGpsTimeout = 60000; // 1 minute
private PendingIntent mPreviousGpsTimer = null;
private long mLastLocationRequested = 0;
private ServiceHandler mHander = null;
private Messenger mMessenger = null;
@ -318,6 +319,9 @@ public class MicroPhotoService extends Service {
mService.registerHeartbeatTimer(mService.mHeartbeatDuration);
try {
mService.detectGpsStatus();
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
if (!connectivityManager.isDefaultNetworkActive()) {
@ -1072,6 +1076,8 @@ public class MicroPhotoService extends Service {
// Set Listener
}
try {
enableGps(true);
mLastLocationRequested = System.currentTimeMillis();
mLocationManager.requestLocationUpdates(mLocateType, 30000, 1, mLocationListener, Looper.getMainLooper());
} catch (Exception ex) {
ex.printStackTrace();
@ -1090,6 +1096,13 @@ public class MicroPhotoService extends Service {
return false;
}
private void detectGpsStatus() {
if (System.currentTimeMillis() - mLastLocationRequested > 10 * 60000) {
// 10minutes close it
enableGps(false);
}
}
public void downloadAndInstall(final String url) {
final Context context = getApplicationContext();

Loading…
Cancel
Save