Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter[Android]: Not able to release App with Manage External Storage Permission

We need to allow users to store files in the external storage and for the same, we use MANAGE_EXTERNAL_STORAGE permission in our application.

Ideally for the android SDK version 30 and above we are using Permission.manageExternalStorage and using Permission.storage for android SDK versions lower than 30 as shown in the below code

  // This func is added to access scope storage to export csv files
  static Future<bool> externalStoragePermission(BuildContext context) async {
    final androidVersion = await DeviceInfoPlugin().androidInfo;

    if ((androidVersion.version.sdkInt ?? 0) >= 30) {
      return await checkManageStoragePermission(context);
    } else {
      return await checkStoragePermission(context);
    }
  }

  static Future<bool> checkManageStoragePermission(BuildContext context) async {
    return (await Permission.manageExternalStorage.isGranted ||
        await Permission.manageExternalStorage.request().isGranted);
  }

  static Future<bool> checkStoragePermission(BuildContext context,
      {String? storageTitle, String? storageSubMessage}) async {
    if (await Permission.storage.isGranted ||
        await Permission.storage.request().isGranted) {
      return true;
    } else {
      openBottomSheet(
        title: storageTitle ?? Str.of(context).storagePermissionRequired,
        message: storageSubMessage ?? Str.of(context).storageSubMessage,
      ).show(context);
      return false;
    }
  }

With the above implementation, everything worked fine while the development and internal release but the Google play console reject the application with the below rejections(Also we have submitted the reason as well for manage_storage permission).

enter image description here

like image 781
Dhaval Kansara Avatar asked Jan 30 '26 11:01

Dhaval Kansara


1 Answers

I found solution for this issue

properly tested in android level less then 11 or greater then 11

First please check this is that android device on your onpressd button like this

if(Platform.isAndroid)
{
  downloadAndSavePDF('your network link');
}

=> and then method

Future<void> downloadAndSavePDF(String pdfUrl, String fileName) async {
final response = await http.get(Uri.parse(pdfUrl));
if (response.contentLength == 0) {
  return Future.value(null);
}
try {
  if (response.statusCode == 200) {
    // Get the downloads directory
    Directory downloadsDirectory =
        Directory('/storage/emulated/0/Download/');
    final File file = File('${downloadsDirectory.path}/$fileName');
    if (file.existsSync()) {
      Navigator.pop(context);
      CustomSnakeBar(errorMessage: 'File already downloaded')
          .snakeBar(context);
      return;
    }
    // Write the PDF content to the file
    await file.writeAsBytes(response.bodyBytes);
    Navigator.pop(context);
    CustomSnakeBar(
            errorMessage: 'PDF downloaded', colorText: ConstColor.green)
        .snakeBar(context);
  } else {
    CustomSnakeBar(errorMessage: ConstString.somethingWentWrong)
        .snakeBar(context);
  }
} catch (e) {
  Navigator.pop(context);
  CustomSnakeBar(errorMessage: ConstString.somethingWentWrong)
      .snakeBar(context);
}
}
like image 132
Abhishek Patel Avatar answered Feb 02 '26 02:02

Abhishek Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!