android 13 permission
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:ffmpeg_kit_flutter_audio/ffmpeg_kit.dart';
|
||||
// import 'package:ffmpeg_kit_flutter_audio/ffmpeg_kit.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
@@ -42,9 +43,19 @@ class RekamScreen extends HookConsumerWidget {
|
||||
final awalan = useState("Info :");
|
||||
|
||||
final isPermissionsGranted = useState<bool>(false);
|
||||
Future<int> _getAndroidVersion() async {
|
||||
if (Platform.isAndroid) {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
return androidInfo.version.sdkInt;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Fungsi untuk meminta izin dan menunggu sampai diberikan
|
||||
int androidVersion() {
|
||||
_getAndroidVersion();
|
||||
return Platform.isAndroid ? int.parse(Platform.version.split('.')[0]) : 0;
|
||||
}
|
||||
|
||||
@@ -52,9 +63,18 @@ class RekamScreen extends HookConsumerWidget {
|
||||
final microphoneStatus = await Permission.microphone.request();
|
||||
|
||||
PermissionStatus storageStatus;
|
||||
Map<Permission, PermissionStatus> statuses = {};
|
||||
|
||||
if (Platform.isAndroid && androidVersion() >= 33) {
|
||||
final androidApiVer = await _getAndroidVersion();
|
||||
|
||||
if (Platform.isAndroid && androidApiVer >= 33) {
|
||||
storageStatus = await Permission.audio.request(); // Untuk Android 13+
|
||||
statuses = await [
|
||||
Permission.microphone,
|
||||
Permission.photos,
|
||||
Permission.videos,
|
||||
Permission.audio,
|
||||
].request();
|
||||
} else {
|
||||
storageStatus =
|
||||
await Permission.storage.request(); // Untuk Android 12 ke bawah
|
||||
@@ -63,6 +83,15 @@ class RekamScreen extends HookConsumerWidget {
|
||||
if (microphoneStatus.isGranted && storageStatus.isGranted) {
|
||||
isPermissionsGranted.value = true;
|
||||
}
|
||||
if (Platform.isAndroid && androidApiVer >= 33) {
|
||||
print("Permission Statuses: ${statuses.toString()}");
|
||||
|
||||
if (statuses.values.every((status) => status.isGranted)) {
|
||||
isPermissionsGranted.value = true;
|
||||
} else {
|
||||
isPermissionsGranted.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
@@ -156,21 +185,21 @@ class RekamScreen extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> convertToMp3(String inputPath) async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final outputPath = "${dir.path}/output.mp3";
|
||||
// Future<String?> convertToMp3(String inputPath) async {
|
||||
// final dir = await getApplicationDocumentsDirectory();
|
||||
// final outputPath = "${dir.path}/output.mp3";
|
||||
|
||||
// Jalankan perintah FFmpeg untuk konversi
|
||||
await FFmpegKit.execute(
|
||||
'-i $inputPath -codec:a libmp3lame -qscale:a 2 $outputPath');
|
||||
// // Jalankan perintah FFmpeg untuk konversi
|
||||
// await FFmpegKit.execute(
|
||||
// '-i $inputPath -codec:a libmp3lame -qscale:a 2 $outputPath');
|
||||
|
||||
// Pastikan file MP3 berhasil dibuat
|
||||
if (File(outputPath).existsSync()) {
|
||||
return outputPath;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// // Pastikan file MP3 berhasil dibuat
|
||||
// if (File(outputPath).existsSync()) {
|
||||
// return outputPath;
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> berhentiRekaman() async {
|
||||
try {
|
||||
@@ -179,15 +208,21 @@ class RekamScreen extends HookConsumerWidget {
|
||||
|
||||
// panggil fungsi untuk kirim ke BE
|
||||
if (audioPath.value.isNotEmpty) {
|
||||
String? mp3Path = await convertToMp3(audioPath.value);
|
||||
if (mp3Path != null) {
|
||||
// String? mp3Path = await convertToMp3(audioPath.value);
|
||||
if (audioPath.value != '') {
|
||||
// await uploadAudioFile(mp3Path);
|
||||
ref.read(uploadRekamProvider.notifier).uploadRekam(
|
||||
host: host,
|
||||
filePath: mp3Path,
|
||||
filePath: audioPath.value,
|
||||
userId: userId,
|
||||
qrCodeStr: qrCodeStr.value,
|
||||
);
|
||||
// ref.read(uploadRekamProvider.notifier).uploadRekam(
|
||||
// host: host,
|
||||
// filePath: mp3Path,
|
||||
// userId: userId,
|
||||
// qrCodeStr: qrCodeStr.value,
|
||||
// );
|
||||
} else {
|
||||
print("Konversi gagal!");
|
||||
showLongToast(
|
||||
|
||||
Reference in New Issue
Block a user