无法请求扑扑的位置许可

时间:2019-04-08 19:27:36

标签: android flutter permissions

我正在使用google_maps_fluttergeolocator创建用于跟踪手机位置的测试应用程序。问题是当我请求位置许可时,不会显示对话框。

我已经尝试了另外两个软件包simple_permissionspermission,这给了我gradle错误,现在我正在尝试permission_handler,但是找不到权限在清单中

我如何寻求许可

await PermissionHandler().requestPermission([PermissionGroup.locationAlways]);

我的android / app / src / main / AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.geolocation">

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

    <application ...
</manifest>

我的android / app / build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.geolocalization"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    compile 'com.google.android.gms:play-services-maps:16.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.1.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.1.1'
}

控制台中的提示

D/permissions_handler(20397): No permissions found in manifest for: $permission
I/flutter (20397): decodePermissionRequestResult called with: value:[{4: 4}]

1 个答案:

答案 0 :(得分:1)

在flutter中使用以下软件包来获取位置许可:Location permission package

首先在(sdk:flutter)行之后将包添加到pubspec.yaml文件:

location_permissions:^ 2.0.5

第二个:在main.dart文件中,将以下几行添加到开头:

import 'package:location_permissions/location_permissions.dart';

PermissionStatus permission = await LocationPermissions().requestPermissions();