diff --git a/android/app/build.gradle b/android/app/build.gradle index c70369baf..1461aeda4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -49,7 +49,7 @@ android { applicationId "com.exptech.dpip" minSdkVersion 26 targetSdkVersion 35 - versionCode 300001305 + versionCode 300001400 versionName flutterVersionName multiDexEnabled true } @@ -90,6 +90,7 @@ flutter { } dependencies { + implementation 'org.maplibre.gl:android-sdk:11.5.2' implementation 'androidx.core:core-splashscreen:1.0.1' implementation 'com.google.android.material:material:1.12.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 554cafb63..ee4ac1737 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -26,11 +26,12 @@ android:name="${applicationName}" android:icon="@mipmap/ic_launcher" android:theme="@style/LaunchTheme" - android:enableOnBackInvokedCallback="true"> + android:enableOnBackInvokedCallback="true" + android:allowBackup="false" + tools:replace="android:allowBackup"> notifyInit() async { channelGroupKey: 'group_evacuation', channelKey: 'evacuation_minor-general-v2', channelName: '避難資訊(一般)', - channelDescription: '所在地(鄉鎮)發布防空、土石流、淹水或堰塞湖避難警訊時', + channelDescription: '所在地(鄉鎮)發布防空、土石流、淹水或堰塞湖避難資訊時', importance: NotificationImportance.High, defaultPrivacy: NotificationPrivacy.Public, playSound: true, @@ -285,7 +285,7 @@ Future notifyInit() async { channelGroupKey: 'group_tsunami', channelKey: 'tsunami-silent-v2', channelName: '太平洋海嘯消息 (無聲通知)', - channelDescription: '地震報告所在地震度 3 以下的地區', + channelDescription: '太平洋海嘯消息發布時', groupAlertBehavior: GroupAlertBehavior.Children, importance: NotificationImportance.Min, defaultPrivacy: NotificationPrivacy.Public, diff --git a/lib/core/service.dart b/lib/core/service.dart index adf337655..0886c01b5 100644 --- a/lib/core/service.dart +++ b/lib/core/service.dart @@ -11,9 +11,9 @@ import 'package:dpip/global.dart'; import 'package:dpip/utils/extensions/latlng.dart'; import 'package:dpip/utils/location_to_code.dart'; import 'package:dpip/utils/log.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; -import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:maplibre_gl/maplibre_gl.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -97,26 +97,24 @@ void _setupPositionListener() { Future _initializeAndroidForegroundService() async { _isAndroidServiceInitialized = true; - const notificationChannel = AndroidNotificationChannel( - 'my_foreground', - '前景自動定位', - description: '前景自動定位', - importance: Importance.low, - ); - - final notifications = FlutterLocalNotificationsPlugin(); - await notifications.initialize( - const InitializationSettings( - iOS: DarwinInitializationSettings(), - android: AndroidInitializationSettings('@mipmap/ic_launcher'), - ), + await AwesomeNotifications().initialize( + null, // 使用預設 launcher icon + [ + NotificationChannel( + channelKey: 'my_foreground', + channelName: '前景自動定位', + channelDescription: '背景定位服務通知', + importance: NotificationImportance.Low, + defaultColor: const Color(0xFF2196f3), + ledColor: Colors.white, + locked: true, + playSound: false, + onlyAlertOnce: true, + ) + ], ); - await notifications - .resolvePlatformSpecificImplementation() - ?.createNotificationChannel(notificationChannel); - await _backgroundService.configure( androidConfiguration: AndroidConfiguration( onStart: _onServiceStart, @@ -146,7 +144,6 @@ Future _onServiceStart(ServiceInstance service) async { GlobalProviders.init(); final locationService = LocationService(); - final notifications = FlutterLocalNotificationsPlugin(); // Setup service event listeners service.on(ServiceEvent.stopService.name).listen((event) { @@ -162,12 +159,16 @@ Future _onServiceStart(ServiceInstance service) async { if (service is AndroidServiceInstance) { // Initialize foreground service and notification await service.setAsForegroundService(); - await notifications.show( - 888, - 'DPIP', - '前景服務啟動中...', - const NotificationDetails( - android: AndroidNotificationDetails('my_foreground', '前景自動定位', icon: '@drawable/ic_stat_name', ongoing: true), + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: 888, + channelKey: 'my_foreground', + title: 'DPIP', + body: '前景服務啟動中...', + notificationLayout: NotificationLayout.Default, + locked: true, + autoDismissible: false, + icon: 'resource://drawable/ic_stat_name', ), ); @@ -183,6 +184,7 @@ Future _onServiceStart(ServiceInstance service) async { // Define the periodic location update task Future updateLocation() async { + _locationUpdateTimer?.cancel(); if (!await service.isForegroundService()) return; // Get current position and location info @@ -209,12 +211,15 @@ Future _onServiceStart(ServiceInstance service) async { final notificationBody = '$timestamp\n$latitude,$longitude $locationName'; service.invoke(ServiceEvent.sendDebug.name, {'notifyBody': notificationBody}); - await notifications.show( - 888, - notificationTitle, - notificationBody, - const NotificationDetails( - android: AndroidNotificationDetails('my_foreground', '前景自動定位', icon: 'ic_stat_name', ongoing: true), + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: 888, + channelKey: 'my_foreground', + title: notificationTitle, + body: notificationBody, + notificationLayout: NotificationLayout.Default, + locked: true, + autoDismissible: false, ), ); service.setForegroundNotificationInfo(title: notificationTitle, content: notificationBody); diff --git a/pubspec.yaml b/pubspec.yaml index b9389ecc1..b9302abd2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: dpip description: "Disaster Prevention Information Platform" publish_to: 'none' -version: 3.0.013 +version: 3.0.014 environment: sdk: '>=3.7.0 <4.0.0' @@ -31,7 +31,6 @@ dependencies: url: https://github.com/ExpTechTW/flutter_background_service.git path: packages/flutter_background_service ref: master - flutter_local_notifications: ^19.1.0 flutter_localizations: sdk: flutter flutter_markdown: ^0.7.7