【问题标题】:Flutter location permission issues in android manifest fileandroid清单文件中的颤振位置权限问题
【发布时间】:2021-11-17 23:08:48
【问题描述】:

我的 Flutter 代码:

 onPressed: () async {
                  Geolocator
                      .getCurrentPosition(desiredAccuracy: LocationAccuracy.best, forceAndroidLocationManager: true)
                      .then((Position position) {
                    setState(() {
                      _currentPosition = position;
                      print ( "LAT: ${_currentPosition.latitude}, LNG: ${_currentPosition.longitude}");
                    });
                  }).catchError((e) {
                    print(e);
                  });
                },

它显示以下内容:

`No location permissions are defined in the manifest. Make sure at least CCESS_FINE_LOCATION` or ACCESS_COARSE_LOCATION are defined in the manifest.

甚至以为我已经在清单中添加了权限

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.agent">
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
   <application
        android:label="agent"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

我有以下无法修复的错误:

这里不允许使用属性 android:icon 未解决的类“MainActivity”

【问题讨论】:

  • 卸载你的应用并运行flutter clean命令然后运行
  • 同样的问题不起作用
  • 你打开Flutter项目的文件夹了吗?打开Android项目文件夹怎么样?

标签: flutter dart android-manifest manifest flutter-android


【解决方案1】:

在里面添加这行

android->app->src->main->AndroidManifest.xml

android->app->src->profile->AndroidManifest.xml

android->app->src->debug->AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- Recommended for Android 9 (API level 28) and lower. -->
<!-- Required for Android 10 (API level 29) and higher. -->
<service
   android:name="MyNavigationService"
   android:foregroundServiceType="location" ... >
<!-- Any inner elements would go here. -->
</service>

Read this article

【讨论】:

    【解决方案2】:

    我在@OmarMohamoud's answer下面添加了一些信息。

    您可以查看geolocator package docs。它谈到了主要的2点

    • 对于 AndroidX 版本的 Android 支持库,添加 2 个属性并检查 SDK 版本。
    • 添加位置权限

    如果您使用的是 Android +10 并且“即使您的应用在后台运行时也希望继续接收更新”,则必须添加此权限: p>

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

    仔细检查文档。

    【讨论】:

      【解决方案3】:

      desiredAccuracy:LocationAccuracy.best 两者都需要

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

      【讨论】:

        【解决方案4】:

        首先,尝试gradle sync。如建议here:

        1. 从 android studio 同步 gradle(必须的步骤)
        2. 扑干净
        3. 颤振酒吧获取
        4. 颤动运行

        其次,如果还是不行,可能是this引起的。要解决这个问题,请在实际使用地理插件之前使用permission_handler 包请求Permission.location 或其他类似权限。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-07
          • 1970-01-01
          • 2012-05-28
          • 2021-11-04
          • 2022-10-04
          • 2012-11-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多