简体   繁体   English

Flutter - Android 在发布模式下不要求许可 - 自动拒绝

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

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.我一直在尝试解决 Android 的无权限问题。 I've developed this app with Flutter and have uploaded it to play store for open testing.我用 Flutter 开发了这个应用程序,并将它上传到 Play 商店进行开放测试。 But, in release mode, it just never asks for permission.但是,在发布模式下,它只是从不征求许可。 Just never.只是从来没有。 No message or log in console/logcat.没有消息或登录控制台/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).当您检查应用程序的权限设置时,您会看到在 Android 7.0、8.0、10 中的每个设备中每次都自动拒绝该权限(未在其他设备中尝试过)。 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 :使用permission_handler包:

     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我在这里找到了没有答案的类似问题 - Flutter 应用程序不会在发布模式下要求存储权限

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.我的应用程序已被 Google Play 商店延迟了 16 天的验证,请提供解决方案,以便我避免进一步延迟。 And No, the flutter clean doesn't help.不, flutter clean无济于事。

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.编辑 -在 pub.dev 上搜索更多用于权限处理的包,我发现permission_plugin也不起作用,同样的问题,但它在 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.我将分享所需的任何代码。

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.这个建议是在官方 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.我相信发生这种情况是因为如该问题线程中所讨论的那样将通道从 master 更改为 stable ,但再次将其更改回来并不能解决问题。 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.开发人员应该真正考虑这个错误/问题。

您是否已将以下代码添加到 android 清单文件中?

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

我也遇到了同样的问题,找不到解决方案,但是当我尝试将 android 模拟器的 API 从 30 API 降低到 28 API 时,它突然起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM