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 8e690f8c
authored
Apr 25, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.0
1 parent
14b3e20d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
32 deletions
app/src/main/java/com/agenew/location_server/application/BirdService.java
app/src/main/java/com/agenew/location_server/application/BirdService.java
View file @
8e690f8
...
@@ -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,21 +566,23 @@ public class BirdService extends Service {
...
@@ -546,21 +566,23 @@ 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"
);
GpsStatus
sta
=
mLocationManager
.
getGpsStatus
(
null
);
if
(
mLocationManager
!=
null
){
if
(
event
==
GpsStatus
.
GPS_EVENT_STARTED
)
{
GpsStatus
sta
=
mLocationManager
.
getGpsStatus
(
null
);
onGpsStarted
();
if
(
event
==
GpsStatus
.
GPS_EVENT_STARTED
)
{
Log
.
d
(
TAG
,
"STARTED"
);
onGpsStarted
();
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_STOPPED
)
{
Log
.
d
(
TAG
,
"STARTED"
);
onGpsStopped
();
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_STOPPED
)
{
Log
.
d
(
TAG
,
"STOPPED"
);
onGpsStopped
();
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_FIRST_FIX
)
{
Log
.
d
(
TAG
,
"STOPPED"
);
onFirstFix
(
sta
.
getTimeToFirstFix
());
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_FIRST_FIX
)
{
Log
.
d
(
TAG
,
"FIRST_FIX"
);
onFirstFix
(
sta
.
getTimeToFirstFix
());
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_SATELLITE_STATUS
)
{
Log
.
d
(
TAG
,
"FIRST_FIX"
);
if
(
isLocationFixed
(
sta
.
getSatellites
())
==
false
)
{
}
else
if
(
event
==
GpsStatus
.
GPS_EVENT_SATELLITE_STATUS
)
{
Log
.
d
(
TAG
,
"UNAVAILABLE"
);
if
(
isLocationFixed
(
sta
.
getSatellites
())
==
false
)
{
}
else
{
Log
.
d
(
TAG
,
"UNAVAILABLE"
);
Log
.
d
(
TAG
,
"AVAILABLE"
);
}
else
{
Log
.
d
(
TAG
,
"AVAILABLE"
);
}
}
}
}
}
}
}
...
...
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