Commit f8ba8e21 by cuiliang.shi

优化

1 parent 6b16c32f
...@@ -6,8 +6,8 @@ android { ...@@ -6,8 +6,8 @@ android {
applicationId "com.agenew.location_server.application" applicationId "com.agenew.location_server.application"
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 3
versionName "1.0" versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
......
...@@ -82,10 +82,10 @@ public class BirdService extends Service { ...@@ -82,10 +82,10 @@ public class BirdService extends Service {
mContext = getApplicationContext(); mContext = getApplicationContext();
// open gps & network. // open gps & network.
// close gps & network.
Intent intent2 = new Intent("com.bird.open_gps_switch"); Intent intent2 = new Intent("com.bird.open_gps_switch");
intent2.addFlags(0x01000000); intent2.addFlags(0x01000000);
sendBroadcast(intent2); sendBroadcast(intent2);
if (DevicePreferences.getInstance(this).getBoolean("is_need_notification", true)){ if (DevicePreferences.getInstance(this).getBoolean("is_need_notification", true)){
String CHANNEL_ONE_ID = "com.primedu.cn"; String CHANNEL_ONE_ID = "com.primedu.cn";
...@@ -111,6 +111,8 @@ public class BirdService extends Service { ...@@ -111,6 +111,8 @@ public class BirdService extends Service {
} }
notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(1, notification); startForeground(1, notification);
}else{ }else{
DevicePreferences.getInstance(this).putBoolean("is_need_notification", true); DevicePreferences.getInstance(this).putBoolean("is_need_notification", true);
} }
...@@ -127,6 +129,7 @@ public class BirdService extends Service { ...@@ -127,6 +129,7 @@ public class BirdService extends Service {
} }
private int mLocationCount = 0;
public AMapLocationListener mLocationListener = new AMapLocationListener() { public AMapLocationListener mLocationListener = new AMapLocationListener() {
@Override @Override
...@@ -134,18 +137,21 @@ public class BirdService extends Service { ...@@ -134,18 +137,21 @@ public class BirdService extends Service {
Log.d(TAG, "onLocationChanged"); Log.d(TAG, "onLocationChanged");
if (amapLocation != null) { if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) { if (amapLocation.getErrorCode() == 0) {
mLocationCount++;
if (mLocationCount > 10){
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mStartTime = dateformat.format(System.currentTimeMillis()); mStartTime = dateformat.format(System.currentTimeMillis());
mLatitude = String.valueOf(amapLocation.getLatitude()); mLatitude = String.valueOf(amapLocation.getLatitude());
mLongitude = String.valueOf(amapLocation.getLongitude()); mLongitude = String.valueOf(amapLocation.getLongitude());
getPhoneInfo();
sendMsg();
if (mLocationClient != null) { if (mLocationClient != null) {
mLocationClient.stopLocation(); mLocationClient.stopLocation();
} }
mLocationCount = 0;
getPhoneInfo();
sendMsg();
}
} else { } else {
// setAlarm(); // setAlarm();
...@@ -186,7 +192,7 @@ public class BirdService extends Service { ...@@ -186,7 +192,7 @@ public class BirdService extends Service {
stopSelf(); stopSelf();
} }
private int mErrorCount = 0;
public void sendMsg() { public void sendMsg() {
Log.d(TAG, "sendMsg"); Log.d(TAG, "sendMsg");
new Thread(new Runnable() { new Thread(new Runnable() {
...@@ -267,8 +273,27 @@ public class BirdService extends Service { ...@@ -267,8 +273,27 @@ public class BirdService extends Service {
} else if (responseCode != 200) { } else if (responseCode != 200) {
Log.d(TAG, "request failed"); Log.d(TAG, "request failed");
} }
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) {
e.printStackTrace(); Log.d(TAG, "Exception:" + e.toString());
mErrorCount++;
if (mErrorCount > 5){
setAlarm();
// close gps & network.
Intent intent = new Intent("com.bird.close_gps_switch");
intent.addFlags(0x01000000);
getApplicationContext().sendBroadcast(intent);
}else{
sendMsg();
}
} finally { } finally {
httpURLConnection.disconnect(); httpURLConnection.disconnect();
Log.d(TAG, "close connect"); Log.d(TAG, "close connect");
...@@ -280,13 +305,6 @@ public class BirdService extends Service { ...@@ -280,13 +305,6 @@ public class BirdService extends Service {
} }
} }
} }
setAlarm();
// close gps & network.
Intent intent = new Intent("com.bird.close_gps_switch");
intent.addFlags(0x01000000);
getApplicationContext().sendBroadcast(intent);
} }
}).start(); }).start();
} }
...@@ -306,7 +324,7 @@ public class BirdService extends Service { ...@@ -306,7 +324,7 @@ public class BirdService extends Service {
mLocationOption = new AMapLocationClientOption(); mLocationOption = new AMapLocationClientOption();
//set model is AMapLocationMode.Battery_Saving //set model is AMapLocationMode.Battery_Saving
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
mLocationOption.setInterval(1000);
mLocationClient.setLocationOption(mLocationOption); mLocationClient.setLocationOption(mLocationOption);
mLocationClient.startLocation(); mLocationClient.startLocation();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!