Commit f8ba8e21 by cuiliang.shi

优化

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