feat(gpsrelaysentinel): 前台服务通知添加GPS数据计数值
- 添加mGpsCount计数器统计GPS数据接收次数 - 每次onLocationChanged时计数器自增 - 通知栏实时显示GPS数据计数值(Count: x) - 计数包含在通知内容中:经纬度 | Count: x
This commit is contained in:
@@ -28,6 +28,7 @@ public class MainService extends Service {
|
|||||||
private static final int NOTIFICATION_ID = 1;
|
private static final int NOTIFICATION_ID = 1;
|
||||||
private static final String PREF_NAME = "gps_relay_service_prefs";
|
private static final String PREF_NAME = "gps_relay_service_prefs";
|
||||||
private static final String KEY_SERVICE_ENABLED = "service_enabled";
|
private static final String KEY_SERVICE_ENABLED = "service_enabled";
|
||||||
|
private int mGpsCount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@@ -67,6 +68,7 @@ public class MainService extends Service {
|
|||||||
mLocationListener = new LocationListener() {
|
mLocationListener = new LocationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
|
mGpsCount++;
|
||||||
String gpsInfo = "Lat: " + location.getLatitude() + ", Lng: " + location.getLongitude();
|
String gpsInfo = "Lat: " + location.getLatitude() + ", Lng: " + location.getLongitude();
|
||||||
LogUtils.d(TAG, "Location changed: " + gpsInfo);
|
LogUtils.d(TAG, "Location changed: " + gpsInfo);
|
||||||
updateNotification(gpsInfo);
|
updateNotification(gpsInfo);
|
||||||
@@ -129,7 +131,7 @@ public class MainService extends Service {
|
|||||||
|
|
||||||
private void updateNotification(String gpsInfo) {
|
private void updateNotification(String gpsInfo) {
|
||||||
if (mNotificationBuilder != null) {
|
if (mNotificationBuilder != null) {
|
||||||
mNotificationBuilder.setContentText(gpsInfo);
|
mNotificationBuilder.setContentText(gpsInfo + " | Count: " + mGpsCount);
|
||||||
mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
|
mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user