checkPermission method
检查并请求麦克风权限
Implementation
Future<bool> checkPermission() async {
final status = await Permission.microphone.status;
debugPrint('麦克风权限状态: $status');
if (status.isGranted) {
debugPrint('麦克风权限已授予');
return true;
}
debugPrint('请求麦克风权限...');
final result = await Permission.microphone.request();
debugPrint('权限请求结果: $result');
if (result.isGranted) {
return true;
}
if (result.isPermanentlyDenied) {
_setError('麦克风权限被永久拒绝,请在设置中开启');
} else {
_setError('请授予麦克风权限');
}
return false;
}