From d4fddaecf95953e40245f94c7a493e4f038be115 Mon Sep 17 00:00:00 2001 From: MiMo Date: Tue, 7 Jul 2026 00:13:26 +0800 Subject: [PATCH] =?UTF-8?q?GPS=E6=8E=A5=E6=94=B6=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=8E=A5=E6=94=B6=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E8=AE=A1=E6=95=B0=E5=B9=B6=E5=9C=A8=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A0=8F=E5=AE=9E=E6=97=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - onCreate初始化gpsReceiveCount计数器归零 - parseAndSaveGpsData每次接收数据后递增计数并刷新通知栏 - 通知栏文本更新为"已接收GPS数据 N 次" --- bytheway/build.properties | 4 ++-- .../bytheway/services/GpsReceiveService.java | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bytheway/build.properties b/bytheway/build.properties index d208450..f9d39e4 100644 --- a/bytheway/build.properties +++ b/bytheway/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Mon Jul 06 20:21:37 CST 2026 +#Mon Jul 06 20:33:32 CST 2026 stageCount=2 libraryProject= baseVersion=15.20 publishVersion=15.20.1 -buildCount=14 +buildCount=16 baseBetaVersion=15.20.2 diff --git a/bytheway/src/main/java/cc/winboll/studio/bytheway/services/GpsReceiveService.java b/bytheway/src/main/java/cc/winboll/studio/bytheway/services/GpsReceiveService.java index c4e0ba0..3012051 100644 --- a/bytheway/src/main/java/cc/winboll/studio/bytheway/services/GpsReceiveService.java +++ b/bytheway/src/main/java/cc/winboll/studio/bytheway/services/GpsReceiveService.java @@ -27,6 +27,7 @@ public class GpsReceiveService extends Service { private static final String CHANNEL_ID = "gps_receive_service_channel"; private static boolean serviceRunning = false; + private int gpsReceiveCount = 0; private BroadcastReceiver gpsServiceBroadcastReceiver; /** @@ -67,13 +68,14 @@ public class GpsReceiveService extends Service { public void onCreate() { super.onCreate(); serviceRunning = true; + gpsReceiveCount = 0; registerGpsServiceBroadcast(); - startForeground(NOTIFICATION_ID, createNotification()); + startForeground(NOTIFICATION_ID, createNotification(gpsReceiveCount)); LogUtils.i("GpsReceiveService", "GPS定位消息接收服务创建完成"); Toast.makeText(this, "GPS定位消息接收服务已开启", Toast.LENGTH_SHORT).show(); } - private Notification createNotification() { + private Notification createNotification(final int count) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( CHANNEL_ID, @@ -85,12 +87,20 @@ public class GpsReceiveService extends Service { } return new Notification.Builder(this, CHANNEL_ID) .setContentTitle("ByTheWay") - .setContentText("GPS定位消息接收服务运行中") + .setContentText("已接收GPS数据 " + count + " 次") .setSmallIcon(android.R.drawable.ic_menu_mylocation) .setOngoing(true) .build(); } + /** + * 更新前台服务通知栏显示 + */ + private void updateNotification() { + final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.notify(NOTIFICATION_ID, createNotification(gpsReceiveCount)); + } + /** * 动态注册GPS定位广播接收器 */ @@ -114,7 +124,9 @@ public class GpsReceiveService extends Service { private void parseAndSaveGpsData(final Intent intent) { final GpsBean bean = GpsUtil.parseFromIntent(intent); GpsUtil.insertGps(getApplicationContext(), bean); - LogUtils.d("GpsReceiveService", "收到GPS广播,已保存定位数据"); + gpsReceiveCount++; + updateNotification(); + LogUtils.d("GpsReceiveService", "收到GPS广播,已保存定位数据,累计接收 " + gpsReceiveCount + " 次"); } @Override