Skip to content

Commit

Permalink
Fix permission fichiers sous Android inférieur à 12
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-perso committed Jun 11, 2024
1 parent 59588d4 commit f4ad2b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/pages/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gal/gal.dart';
import 'package:lucide_icons/lucide_icons.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:stendmobile/utils/format_bytes.dart';
import 'package:stendmobile/utils/format_date.dart';
import 'package:stendmobile/utils/send_notification.dart';
Expand Down Expand Up @@ -718,6 +720,27 @@ class _DownloadPageState extends State<DownloadPage> with AutomaticKeepAliveClie
return;
}

// Si on est sur Android, on demande la permission de stockage
if (Platform.isAndroid) {
// Si on est sur une version inférieure à Android 13, on demande la permission
var deviceInfo = DeviceInfoPlugin();
var androidInfo = await deviceInfo.androidInfo;
debugPrint("sdkInt: ${androidInfo.version.sdkInt}");
if(androidInfo.version.sdkInt < 33) {
debugPrint("SDK inférieur à 33, on demande la permission de stockage");
var storagePermission = await Permission.storage.request();
if (storagePermission != PermissionStatus.granted) {
if (!mounted) return;
Haptic().error();
showSnackBar(context, "Vous devez autoriser l'accès au stockage pour télécharger les fichiers", icon: "error", useCupertino: widget.useCupertino);
Navigator.pop(context);
return;
}
} else {
debugPrint("SDK supérieur ou égal à 33, on ne demande pas la permission de stockage");
}
}

// On détermine le chemin du fichier où télécharger
String downloadDirectory = Platform.isAndroid ? '/storage/emulated/0/Download' : (await getApplicationDocumentsDirectory()).path;
if (Platform.isIOS != true && box.read('downloadInSubFolder') == true) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/send_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void askNotifPermission() async {
if(Platform.isAndroid){
// Si on sur Android 12 ou -, on ne demande pas la permission
var deviceInfo = DeviceInfoPlugin();
var androidInfo = await deviceInfo.androidInfo; // on utilisera ça pdnt l'upload pour un user agent plus précis
var androidInfo = await deviceInfo.androidInfo;
debugPrint("SDK Android: ${androidInfo.version.sdkInt}");
if(androidInfo.version.sdkInt <= 32) return;

Expand Down

0 comments on commit f4ad2b9

Please sign in to comment.