Commit 8e690f8c by cuiliang.shi

2.0

1 parent 14b3e20d
...@@ -60,8 +60,8 @@ import java.util.List; ...@@ -60,8 +60,8 @@ import java.util.List;
public class BirdService extends Service { public class BirdService extends Service {
public static int status = 0; public static int status = 0;
private final static String DEFAULTPATH = "http://202.100.190.58:8090/api/cstmzPosition"; private final String DEFAULTPATH = "http://202.100.190.58:8090/api/cstmzPosition";
private final static long DEFAULTINTERVAL = 30; private final long DEFAULTINTERVAL = 30;
private String mMobile; private String mMobile;
private String mIMEIStr; private String mIMEIStr;
private String mICCIDStr; private String mICCIDStr;
...@@ -230,6 +230,10 @@ public class BirdService extends Service { ...@@ -230,6 +230,10 @@ public class BirdService extends Service {
if (mLocationClient != null) { if (mLocationClient != null) {
mLocationClient.stopLocation(); mLocationClient.stopLocation();
} }
handleGpsRelease();
mLocationCount = 0; mLocationCount = 0;
getPhoneInfo(); getPhoneInfo();
postLocationInfo(); postLocationInfo();
...@@ -251,10 +255,29 @@ public class BirdService extends Service { ...@@ -251,10 +255,29 @@ public class BirdService extends Service {
} }
}; };
private void handleGpsRelease() {
if (mLocationClient != null) {
mLocationClient.stopLocation();
}
// Android 7.0 GnssStatusListenerTransport Message. eg: https://www.jianshu.com/p/1b6a66020555
if (mLocListener != null){
mLocationManager.removeUpdates(mLocListener);
mLocListener = null;
}
if (mGpsListener != null){
mLocationManager.removeGpsStatusListener(mGpsListener);
mGpsListener = null;
}
mLocationManager = null;
}
private void handlerGpsError() { private void handlerGpsError() {
Log.d(TAG, "handlerGpsError"); Log.d(TAG, "handlerGpsError");
mErrorCount++; mErrorCount++;
if (mErrorCount > 6){ if (mErrorCount > 6){
handleGpsRelease();
setAlarm(); setAlarm();
} }
} }
...@@ -278,10 +301,10 @@ public class BirdService extends Service { ...@@ -278,10 +301,10 @@ public class BirdService extends Service {
manger.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pendingIntent2); manger.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pendingIntent2);
} }
if (!mHasSendTheLocationInfo){ /* if (!mHasSendTheLocationInfo){
setNetworkListener(); mNetworkListenerHandler.sendEmptyMessageDelayed(0, 10000);
return; return;
} }*/
stopForeground(true); stopForeground(true);
Log.d(TAG, "time:" + new Date().toString()); Log.d(TAG, "time:" + new Date().toString());
...@@ -397,16 +420,11 @@ public class BirdService extends Service { ...@@ -397,16 +420,11 @@ public class BirdService extends Service {
setAlarm(); setAlarm();
// close gps & network.
Intent intent = new Intent("com.bird.close_gps_switch");
intent.addFlags(0x01000000);
getApplicationContext().sendBroadcast(intent);
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "Exception:" + e.toString()); Log.d(TAG, "Exception:" + e.toString());
mErrorCount++; mErrorCount++;
if (mErrorCount > 5){ if (mErrorCount > 5){
handleGpsRelease();
setAlarm(); setAlarm();
}else{ }else{
long temp = DevicePreferences.getInstance(mContext).getLong("bird_location_upload_interval", DEFAULTINTERVAL); long temp = DevicePreferences.getInstance(mContext).getLong("bird_location_upload_interval", DEFAULTINTERVAL);
...@@ -474,19 +492,21 @@ public class BirdService extends Service { ...@@ -474,19 +492,21 @@ public class BirdService extends Service {
@Override @Override
public void onDestroy() { public void onDestroy() {
mLocationManager.removeUpdates(mLocListener);
mLocationManager.removeGpsStatusListener(mGpsListener);
if (isRegistered) { if (isRegistered) {
unregisterReceiver(netWorkChangReceiver); unregisterReceiver(netWorkChangReceiver);
} }
// close gps & network.
Intent intent = new Intent("com.bird.close_gps_switch");
intent.addFlags(0x01000000);
getApplicationContext().sendBroadcast(intent);
super.onDestroy(); super.onDestroy();
Log.d(TAG, "onDestory"); Log.d(TAG, "onDestory");
} }
public final LocationListener mLocListener = new LocationListener() { public LocationListener mLocListener = new LocationListener() {
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
Log.v(TAG, "Enter onLocationChanged function"); Log.v(TAG, "Enter onLocationChanged function");
...@@ -509,7 +529,7 @@ public class BirdService extends Service { ...@@ -509,7 +529,7 @@ public class BirdService extends Service {
Log.v(TAG, "Enter showGpsStatus function"); Log.v(TAG, "Enter showGpsStatus function");
} }
public final GpsStatus.Listener mGpsListener = new GpsStatus.Listener() { public GpsStatus.Listener mGpsListener = new GpsStatus.Listener() {
private void onFirstFix(int ttff) { private void onFirstFix(int ttff) {
Log.v(TAG, "Enter onFirstFix function: ttff = " + ttff); Log.v(TAG, "Enter onFirstFix function: ttff = " + ttff);
...@@ -546,6 +566,7 @@ public class BirdService extends Service { ...@@ -546,6 +566,7 @@ public class BirdService extends Service {
public void onGpsStatusChanged(int event) { public void onGpsStatusChanged(int event) {
Log.v(TAG, "Enter onGpsStatusChanged function"); Log.v(TAG, "Enter onGpsStatusChanged function");
if (mLocationManager != null){
GpsStatus sta = mLocationManager.getGpsStatus(null); GpsStatus sta = mLocationManager.getGpsStatus(null);
if (event == GpsStatus.GPS_EVENT_STARTED) { if (event == GpsStatus.GPS_EVENT_STARTED) {
onGpsStarted(); onGpsStarted();
...@@ -564,6 +585,7 @@ public class BirdService extends Service { ...@@ -564,6 +585,7 @@ public class BirdService extends Service {
} }
} }
} }
}
}; };
private void searchGPS() { private void searchGPS() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!