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 d96ff9f6
authored
Apr 17, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
搜星版本
1 parent
01b49513
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
38 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 @
d96ff9f
package
com
.
agenew
.
location_server
.
application
;
package
com
.
agenew
.
location_server
.
application
;
import
android.annotation.SuppressLint
;
import
android.app.AlarmManager
;
import
android.app.AlarmManager
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.app.NotificationChannel
;
import
android.app.NotificationChannel
;
...
@@ -9,14 +10,23 @@ import android.app.Service;
...
@@ -9,14 +10,23 @@ import android.app.Service;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.location.GpsSatellite
;
import
android.location.GpsStatus
;
import
android.location.Location
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.os.IBinder
;
import
android.os.Message
;
import
android.os.SystemClock
;
import
android.os.SystemClock
;
import
android.provider.Settings
;
import
android.provider.Settings
;
import
android.support.annotation.RequiresApi
;
import
android.support.annotation.RequiresApi
;
import
android.telephony.SubscriptionInfo
;
import
android.telephony.SubscriptionInfo
;
import
android.telephony.SubscriptionManager
;
import
android.telephony.SubscriptionManager
;
import
android.util.Log
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.amap.api.location.AMapLocation
;
import
com.amap.api.location.AMapLocation
;
import
com.amap.api.location.AMapLocationClient
;
import
com.amap.api.location.AMapLocationClient
;
...
@@ -57,18 +67,14 @@ public class BirdService extends Service {
...
@@ -57,18 +67,14 @@ public class BirdService extends Service {
private
String
mPath
=
""
;
private
String
mPath
=
""
;
private
int
ret_code
=
0
;
private
int
ret_code
=
0
;
private
String
ret_cfgv
=
"2019031512"
;
private
String
ret_cfgv
=
"2019031512"
;
private
LocationManager
mLocationManager
;
private
int
mNewMsgCount
=
0
;
@Override
@Override
public
IBinder
onBind
(
Intent
intent
)
{
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
return
null
;
}
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
Log
.
d
(
TAG
,
"onDestory"
);
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
O
)
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
O
)
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
...
@@ -86,37 +92,6 @@ public class BirdService extends Service {
...
@@ -86,37 +92,6 @@ public class BirdService extends Service {
intent2
.
addFlags
(
0x01000000
);
intent2
.
addFlags
(
0x01000000
);
sendBroadcast
(
intent2
);
sendBroadcast
(
intent2
);
// if (DevicePreferences.getInstance(this).getBoolean("is_need_notification", true)){
// String CHANNEL_ONE_ID = "com.primedu.cn";
// String CHANNEL_ONE_NAME = "Channel One";
// NotificationChannel notificationChannel = null;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,
// CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_HIGH);
// notificationChannel.enableLights(true);
// notificationChannel.setLightColor(Color.RED);
// notificationChannel.setShowBadge(true);
// notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
// NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// manager.createNotificationChannel(notificationChannel);
// }
//
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
// Notification notification = null;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// notification = new Notification.Builder(this).setChannelId(CHANNEL_ONE_ID)
// .setContentIntent(pendingIntent)
// .getNotification();
// }
// notification.flags |= Notification.FLAG_NO_CLEAR;
// startForeground(1, notification);
//
// }else{
// DevicePreferences.getInstance(this).putBoolean("is_need_notification", true);
// }
ret_cfgv
=
DevicePreferences
.
getInstance
(
getApplicationContext
()).
getString
(
"bird_ret_cfgv"
,
"2019031512"
);
ret_cfgv
=
DevicePreferences
.
getInstance
(
getApplicationContext
()).
getString
(
"bird_ret_cfgv"
,
"2019031512"
);
mPath
=
DevicePreferences
.
getInstance
(
mContext
).
getString
(
"bird_location_upload_url"
,
DEFAULTPATH
);
mPath
=
DevicePreferences
.
getInstance
(
mContext
).
getString
(
"bird_location_upload_url"
,
DEFAULTPATH
);
long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
...
@@ -124,11 +99,21 @@ public class BirdService extends Service {
...
@@ -124,11 +99,21 @@ public class BirdService extends Service {
Log
.
d
(
TAG
,
"CONFIG - PARAM, time minutes: "
+
temp
Log
.
d
(
TAG
,
"CONFIG - PARAM, time minutes: "
+
temp
+
", cfgv: "
+
ret_cfgv
+
", path: "
+
mPath
);
+
", cfgv: "
+
ret_cfgv
+
", path: "
+
mPath
);
initLocation
(
mContext
);
searchGPS
();
mHandler
.
sendEmptyMessageDelayed
(
0
,
1000
*
60
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
}
@SuppressLint
(
"HandlerLeak"
)
private
Handler
mHandler
=
new
Handler
(){
@Override
public
void
handleMessage
(
Message
msg
)
{
initLocation
(
mContext
);
}
};
private
int
mLocationCount
=
0
;
private
int
mLocationCount
=
0
;
public
AMapLocationListener
mLocationListener
=
new
AMapLocationListener
()
{
public
AMapLocationListener
mLocationListener
=
new
AMapLocationListener
()
{
...
@@ -348,4 +333,122 @@ public class BirdService extends Service {
...
@@ -348,4 +333,122 @@ public class BirdService extends Service {
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
""
);
mModel
=
temp_model
.
trim
().
replaceAll
(
" "
,
""
);
}
}
@Override
public
void
onDestroy
()
{
mLocationManager
.
removeUpdates
(
mLocListener
);
mLocationManager
.
removeGpsStatusListener
(
mGpsListener
);
super
.
onDestroy
();
Log
.
d
(
TAG
,
"onDestory"
);
}
public
final
LocationListener
mLocListener
=
new
LocationListener
()
{
public
void
onLocationChanged
(
Location
location
)
{
Log
.
v
(
TAG
,
"Enter onLocationChanged function"
);
}
public
void
onProviderDisabled
(
String
provider
)
{
Log
.
v
(
TAG
,
"Enter onProviderDisabled function"
);
}
public
void
onProviderEnabled
(
String
provider
)
{
Log
.
v
(
TAG
,
"Enter onProviderEnabled function"
);
}
public
void
onStatusChanged
(
String
provider
,
int
status
,
Bundle
extras
)
{
Log
.
v
(
TAG
,
"Enter onStatusChanged function"
);
}
};
private
void
showGpsStatus
(
CharSequence
txt
,
int
duration
)
{
Log
.
v
(
TAG
,
"Enter showGpsStatus function"
);
}
public
final
GpsStatus
.
Listener
mGpsListener
=
new
GpsStatus
.
Listener
()
{
private
void
onFirstFix
(
int
ttff
)
{
Log
.
v
(
TAG
,
"Enter onFirstFix function: ttff = "
+
ttff
);
CharSequence
txt
=
new
String
(
"GPS Fix after "
+
ttff
+
"ms"
);
showGpsStatus
(
txt
,
Toast
.
LENGTH_LONG
);
}
private
void
onGpsStarted
()
{
Log
.
v
(
TAG
,
"Enter onGpsStarted function"
);
CharSequence
txt
=
new
String
(
"GPS started"
);
showGpsStatus
(
txt
,
Toast
.
LENGTH_SHORT
);
}
private
void
onGpsStopped
()
{
Log
.
v
(
TAG
,
"Enter onGpsStopped function"
);
CharSequence
txt
=
new
String
(
"GPS stopped"
);
showGpsStatus
(
txt
,
Toast
.
LENGTH_SHORT
);
}
private
boolean
isLocationFixed
(
Iterable
<
GpsSatellite
>
list
)
{
boolean
fixed
=
false
;
synchronized
(
this
)
{
int
index
=
0
;
for
(
GpsSatellite
sate
:
list
)
{
if
(
sate
.
usedInFix
())
{
fixed
=
true
;
break
;
}
index
++;
}
}
return
fixed
;
}
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"
);
}
}
}
};
private
void
searchGPS
()
{
try
{
mLocationManager
=
(
LocationManager
)
getSystemService
(
Context
.
LOCATION_SERVICE
);
if
(
mLocationManager
!=
null
)
{
mLocationManager
.
requestLocationUpdates
(
"gps"
,
0
,
0
,
mLocListener
);
mLocationManager
.
addGpsStatusListener
(
mGpsListener
);
if
(
mLocationManager
.
isProviderEnabled
(
"gps"
))
{
Log
.
d
(
TAG
,
"gps"
+
" enabled"
);
}
else
{
Log
.
d
(
TAG
,
"gps"
+
" disabled"
);
}
Log
.
d
(
TAG
,
"UNKNOWN"
);
}
else
{
Log
.
w
(
TAG
,
"new mLocationManager failed"
);
}
}
catch
(
SecurityException
e
)
{
Toast
.
makeText
(
this
,
"security exception"
,
Toast
.
LENGTH_LONG
)
.
show
();
Log
.
w
(
TAG
,
"Exception: "
+
e
.
getMessage
());
}
catch
(
IllegalArgumentException
e
)
{
Log
.
w
(
TAG
,
"Exception: "
+
e
.
getMessage
());
}
}
}
}
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