askVideoCallPermissions static method
Implementation
static Future<bool> askVideoCallPermissions(BuildContext context) async {
var info = await PackageInfo.fromPlatform();
final microphone = await Permission.microphone.status; //RECORD_AUDIO
final phone = await Permission.phone.status; //READ_PHONE_STATE
final bluetoothConnect =
await Permission.bluetoothConnect.status; //BLUETOOTH_CONNECT
final camera = await Permission.camera.status; //CAMERA
var permissions = <Permission>[];
if(!camera.isGranted && !SessionManagement.getBool(Constants.cameraPermissionAsked)){
permissions.add(Permission.camera);
}
if(!microphone.isGranted && !SessionManagement.getBool(Constants.audioRecordPermissionAsked)){
permissions.add(Permission.microphone);
}
if(!phone.isGranted && !SessionManagement.getBool(Constants.readPhoneStatePermissionAsked)){
permissions.add(Permission.phone);
}
if(!bluetoothConnect.isGranted && !SessionManagement.getBool(Constants.bluetoothPermissionAsked)){
permissions.add(Permission.bluetoothConnect);
}
if ((microphone != PermissionStatus.granted) || (phone != PermissionStatus.granted) || (camera != PermissionStatus.granted) || (bluetoothConnect != PermissionStatus.granted)) {
var shouldShowRequestRationale = ((await Permission.camera.shouldShowRequestRationale) ||
(await Permission.microphone.shouldShowRequestRationale)
|| (await Permission.phone.shouldShowRequestRationale) ||
(await Permission.bluetoothConnect.shouldShowRequestRationale));
LogMessage.d("shouldShowRequestRationale video", shouldShowRequestRationale);
LogMessage.d("SessionManagement.getBool(Constants.cameraPermissionAsked) video", SessionManagement.getBool(Constants.cameraPermissionAsked));
var alreadyAsked = (SessionManagement.getBool(Constants.cameraPermissionAsked) &&
SessionManagement.getBool(Constants.audioRecordPermissionAsked)
&& SessionManagement.getBool(Constants.readPhoneStatePermissionAsked) &&
SessionManagement.getBool(Constants.bluetoothPermissionAsked));
LogMessage.d("alreadyAsked video", alreadyAsked);
if (shouldShowRequestRationale) {
if(context.mounted) {
return requestAudioCallPermissions(permissions: permissions, context: context);
}else{
return Future.value(false);
}
} else if (alreadyAsked) {
if(context.mounted) {
var popupValue = await customPermissionDialog(
icon: recordAudioVideoPermission,
content: getPermissionAlertMessage("video_call"),
appName: info.appName,
context: context);
if (popupValue) {
openAppSettings();
return false;
} else {
return false;
}
}else{
LogMessage.d("requestAudioCallPermissions customPermissionDialog", "Context is Not Mounted");
return false;
}
} else {
if(permissions.isNotEmpty) {
if(context.mounted) {
return requestAudioCallPermissions(permissions: permissions, context: context);
}else{
return Future.value(false);
}
}else{
if(context.mounted) {
var popupValue = await customPermissionDialog(
icon: recordAudioVideoPermission,
content: getPermissionAlertMessage("video_call"),
appName: info.appName,
context: context);
if (popupValue) {
openAppSettings();
return false;
} else {
return false;
}
}else{
LogMessage.d("askVideoCallPermissions", "Context is Not Mounted");
return false;
}
}
}
}else{
return true;
}
}