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