Flutter 地理定位器,清單中未定義位置權限。確保清單中至少定義了 ACCESS_FINE_LOCATION 或.... (Flutter geolocator, No location permissions defined in manifest. Make sure at least ACCESS_FINE_LOCATION or.... are defined in the manifest)


問題描述

Flutter 地理定位器,清單中未定義位置權限。確保清單中至少定義了 ACCESS_FINE_LOCATION 或.... (Flutter geolocator, No location permissions defined in manifest. Make sure at least ACCESS_FINE_LOCATION or.... are defined in the manifest)

我在顫振中使用地理定位器,我在清單文件中定義了權限,但它一直告訴我我沒有。

清單文件:

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


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

地理定位器代碼:

class _LoadingScreenState extends State<LoadingScreen> {

  void getLocation() async{
    bool serviceEnabled;
    LocationPermission permission;

    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      return Future.error('Location services are disabled.');
    }

    permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.deniedForever) {
      return Future.error(
          'Location permissions are permantly denied, we cannot request permissions.');
    }

    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission != LocationPermission.whileInUse &&
          permission != LocationPermission.always) {
        return Future.error(
            'Location permissions are denied (actual value: $permission).');
      }
    }
    Position position= await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
    print(permission);
    print(position);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: (){
            getLocation();
          },
          child: Text('Get Location'),
        ),
      ),
    );
  }
}

我正在我的物理設備上測試應用程序。請告訴我我應該怎麼做才能使它起作用。


參考解法

方法 1:

The only thing wrong is the string inside "android.name".

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

The correct is:

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

方法 2:

Before getting any location ask for permission first:

  await Geolocator.requestPermission();

(by hibauser16096259Valters Šverns)

參考文件

  1. Flutter geolocator, No location permissions defined in manifest. Make sure at least ACCESS_FINE_LOCATION or.... are defined in the manifest (CC BY‑SA 2.5/3.0/4.0)

#Flutter #flutter-dependencies






相關問題

Flutter:構建 APK 時如何傳遞 Gradle 參數? (Flutter: how do I pass Gradle params when building an APK?)

自行更新的 Flutter 模型 (Flutter model that updates itself)

在 Flutter for Web 應用程序中嵌入網頁作為 Widget(類似於 iframe) (Embed a web page as a Widget inside Flutter for Web application (similar to iframe))

顫振無線電值在步進器中沒有改變 (Flutter Radio Value not Changing in Stepper)

Flutter - 使用收到的每條消息通知的實時消息應用程序的最佳方式? (Flutter - Best way to do real-time messaging app with notifications per received message?)

Flutter 在執行異步等待任務時顯示一個小部件 (Flutter show a widget while an async await task is being executed)

嘗試在 Flutter 中訪問 Hive 數據庫時,“聯繫人”框已打開且類型為 Box<Contact> (The box "contacts" is already open and of type Box<Contact> when trying to access Hive database in flutter)

如何在 Flutter MultiImagePicker 中指定照片的質量? (How can i specify the quality of the photo in Flutter MultiImagePicker?)

Swift pod 還不能集成為靜態庫 (Swift pods cannot yet be integrated as static libraries)

為什麼我可以通過 android 模擬器運行一個簡單的計數器應用程序,但不能通過 ios 模擬器運行? (Why can I run a simple counter application through an android simulator but not through an ios simulator?)

DropdownButtonFormField 不顯示選擇顫振的值 (DropdownButtonFormField dosn't show the value that selected flutter)

如何在 Flutter 中獲得手動相機對焦 (How to get manual camera focus in Flutter)







留言討論