Commit 8e690f8c by cuiliang.shi

2.0

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