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

烈酒焚心 提交于 2020-12-12 06:15:44

问题


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.


回答1:


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.




回答2:


Have you added the below code to android manifest file?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


来源:https://stackoverflow.com/questions/64170696/flutter-android-doesnt-ask-for-permission-in-release-mode-auto-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!