init
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<application
|
||||
android:label="SMS Monitor"
|
||||
|
||||
@@ -132,8 +132,18 @@ class _SmsListScreenState extends State<SmsListScreen> {
|
||||
|
||||
if (newVal) {
|
||||
// Request notification permission for foreground service
|
||||
await Permission.notification.request();
|
||||
_startForegroundService();
|
||||
final notifResult = await FlutterForegroundTask.requestNotificationPermission();
|
||||
if (notifResult != NotificationPermission.granted) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('需要通知权限才能保持后台运行')),
|
||||
);
|
||||
}
|
||||
settings.setAutoUpload(false);
|
||||
setState(() {});
|
||||
return;
|
||||
}
|
||||
await _startForegroundService();
|
||||
_startAutoUpload();
|
||||
} else {
|
||||
_stopForegroundService();
|
||||
@@ -143,12 +153,20 @@ class _SmsListScreenState extends State<SmsListScreen> {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _startForegroundService() {
|
||||
FlutterForegroundTask.startService(
|
||||
Future<void> _startForegroundService() async {
|
||||
final result = await FlutterForegroundTask.startService(
|
||||
serviceId: 888,
|
||||
notificationTitle: 'SMS Monitor',
|
||||
notificationText: '正在监听新短信...',
|
||||
callback: startCallback,
|
||||
);
|
||||
if (result is ServiceRequestFailure && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('后台服务启动失败: ${result.error}')),
|
||||
);
|
||||
settings.setAutoUpload(false);
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
void _stopForegroundService() {
|
||||
|
||||
@@ -40,7 +40,7 @@ router.post('/upload', (req, res: Response) => {
|
||||
|
||||
router.get('/', (req, res: Response) => {
|
||||
const page = Math.max(1, parseInt(req.query.page as string) || 1);
|
||||
const limit = Math.min(100, Math.max(1, parseInt(req.query.limit as string) || 20));
|
||||
const limit = Math.min(999999, Math.max(1, parseInt(req.query.limit as string) || 20));
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
let where = 'WHERE 1=1';
|
||||
|
||||
Reference in New Issue
Block a user