You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import 'package:get/get.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'dart:io' show Platform;
|
|
|
|
class PermissionController extends GetxController {
|
|
@override
|
|
void onReady() async {
|
|
super.onReady();
|
|
await requestPermissions();
|
|
}
|
|
|
|
Future<void> requestPermissions() async {
|
|
if (Platform.isAndroid || Platform.isIOS) {
|
|
// 请求所有必要的权限
|
|
final permissions = [
|
|
Permission.microphone,
|
|
Permission.storage,
|
|
Permission.bluetooth,
|
|
Permission.bluetoothConnect,
|
|
];
|
|
|
|
// Android 13+ 需要额外请求 POST_NOTIFICATIONS 权限
|
|
if (Platform.isAndroid) {
|
|
permissions.add(Permission.notification);
|
|
}
|
|
|
|
// 请求权限并打印结果
|
|
final statuses = await permissions.request();
|
|
|
|
// 打印权限状态,便于调试
|
|
statuses.forEach((permission, status) {
|
|
print('权限 $permission: $status');
|
|
});
|
|
|
|
// 请求悬浮窗权限(需要特殊处理)
|
|
if (Platform.isAndroid) {
|
|
if (!await Permission.systemAlertWindow.isGranted) {
|
|
print('请求悬浮窗权限');
|
|
final status = await Permission.systemAlertWindow.request();
|
|
print('悬浮窗权限状态: $status');
|
|
} else {
|
|
print('悬浮窗权限已授予');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|