Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
石璀亮
/
agenew_a16_sos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f8ba8e21
authored
Apr 15, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
1 parent
6b16c32f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
app/build.gradle
app/src/main/java/com/agenew/location_server/application/BirdService.java
app/build.gradle
View file @
f8ba8e2
...
@@ -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
{
...
...
app/src/main/java/com/agenew/location_server/application/BirdService.java
View file @
f8ba8e2
...
@@ -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
)
{
SimpleDateFormat
dateformat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
mLocationCount
++;
mStartTime
=
dateformat
.
format
(
System
.
currentTimeMillis
());
if
(
mLocationCount
>
10
){
SimpleDateFormat
dateformat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
mLatitude
=
String
.
valueOf
(
amapLocation
.
getLatitude
());
mStartTime
=
dateformat
.
format
(
System
.
currentTimeMillis
());
mLongitude
=
String
.
valueOf
(
amapLocation
.
getLongitude
());
mLatitude
=
String
.
valueOf
(
amapLocation
.
getLatitude
());
getPhoneInfo
();
mLongitude
=
String
.
valueOf
(
amapLocation
.
getLongitude
());
sendMsg
();
if
(
mLocationClient
!=
null
)
{
mLocationClient
.
stopLocation
();
if
(
mLocationClient
!=
null
)
{
}
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
();
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment