Flutter - Android doesn't ask for permission in release mode - Auto denied

2,276

I've solved this problem by creating a new project and copying the code in it. This suggestion was found on a similar issue of Official Flutter Github Repo. I believe this happens because of changing the channel to stable from master as discussed in that issue thread but changing it back again doesn't solve the problem. I also looked everywhere related to the plugin exception but no answer/solution worked.

This bug/issue should really be looked upon by the developers.

Share:
2,276
Lalit Fauzdar
Author by

Lalit Fauzdar

Entrepreneur, Full Stack Developer, Bachelors in Computer Science Engineering and Masters in MBA(Finance & Marketing), Content writer, Graphics designer.

Updated on December 24, 2022

Comments

  • Lalit Fauzdar
    Lalit Fauzdar over 1 year

    After stopping myself from asking this question for a week, here I am. I've been trying to resolve the no permission issue of Android. I've developed this app with Flutter and have uploaded it to play store for open testing. But, in release mode, it just never asks for permission. Just never. No message or log in console/logcat.

    I've tried using two-three packages of flutter for the same but none worked. It works flawlessly in debug mode, the permission pop-up comes, you allow it and functions work as they should be. In case of release build, the pop-up doesn't come. When you check app's permissions settings, you see that the permission has been auto-denied every time in every device in Android 7.0, 8.0, 10 (not tried in others). Even after allowing the permission from settings, it doesn't work and permission gets denied again.

    Code I've used:

    1. With permission package :

      var permissionStatus =
          await Permission.getPermissionsStatus([PermissionName.Storage]);
      print(permissionStatus.toString());
      if (permissionStatus.first.permissionStatus == PermissionStatus.allow) {
        _saveFile();
      } else {
        var permissions =
            await Permission.requestPermissions([PermissionName.Storage]);
        print(permissions.first.permissionStatus.toString());
        if (permissions.first.permissionStatus == PermissionStatus.allow)
          _saveFile();
        else
          Fluttertoast.showToast(
              msg: "Storage permission required to share!",
              toastLength: Toast.LENGTH_LONG,
              gravity: ToastGravity.BOTTOM,
              timeInSecForIosWeb: 2,
              backgroundColor: greyColor,
              textColor: Colors.white,
              fontSize: 16.0);
      }
      
    2. With permission_handler package :

      if (await permissionsService.hasStoragePermission()) {
         print("Saving file");
        _saveFile();
      } else {
      final PermissionHandler _permissionHandler = PermissionHandler();
      
      var permission =
        Platform.isAndroid ? PermissionGroup.storage : PermissionGroup.photos;
      var result = await _permissionHandler.requestPermissions([permission]);
      
      if (result[permission] == PermissionStatus.granted)
         _saveFile();
      else
        Fluttertoast.showToast(
          msg: "Storage permission required to share!",
          toastLength: Toast.LENGTH_LONG,
          gravity: ToastGravity.BOTTOM,
          timeInSecForIosWeb: 2,
          backgroundColor: greyColor,
          textColor: Colors.white,
          fontSize: 16.0);
      

    I've also tried using Permission Service.

    I found similar question with no answer here - Flutter app wont ask for Storage permission in release mode

    My app has already been delayed by Google play Store by taking 16 days to verify, please provide a solution so I can avoid further delay. And No, the flutter clean doesn't help.

    EDIT - Searching for more packages for permission handling on pub.dev, I found permission_plugin which also doesn't work, same issue but it gives an error in logcat.

    The error -

    2020-10-02 23:54:44.289 16214-16260/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception:
        MissingPluginException(No implementation found for method check-permissions on channel permissions_plugin)
    #0  MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157)
        <asynchronous suspension>
    #1  PermissionsPlugin.checkPermissions (package:permissions_plugin/permissions_plugin.dart:69)
        <asynchronous suspension>
    #2   _CertificateState._saveImage (package:app_name/screens/app_screen.dart:211)
        <asynchronous suspension>
    

    Update : This error comes with other permission packages as well. Now, I believe this is the cause of the problem. I'll share any piece of code required.

  • Lalit Fauzdar
    Lalit Fauzdar over 3 years
    Obviously. I told you it's working in Debug, that's because these storage permissions are already there. Thanks anyway.
  • Abhishek Ghaskata
    Abhishek Ghaskata over 3 years
    sorry didn't notice.
  • M.M.Hasibuzzaman
    M.M.Hasibuzzaman over 3 years
    This actually worked........ i went to and back from dev to stable a few times, i never thought it would cause problems. Copying files on a new project fixed the issue for me