【问题标题】:Problem with Accessing hidden method. Android, Flutter, Geolocator访问隐藏方法的问题。 Android,颤振,地理定位器
【发布时间】:2020-07-09 16:51:35
【问题描述】:

我正在 Udemy 上学习这门 Flutter/Dart 课程,在开始一个新项目时,我一直在尝试使用 Geolocater Package。最初的 github 项目位于 here

课程的第一步是导入Geolocator包,将其添加到pubspec.yml,然后在screens/loading_screen.dart文件的_LoadingScreenState中添加一个函数:

void getLocation() async {
  Position position = await Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
  print(position);
}

最后你只需添加 getLocation();到同一页面上的 onPressed。在本教程中,这很好用,因为我相信他们使用的是 API 26 和 Geolocator 版本 3.0.1。但是,我使用的是 API 29 或 30(均无效),但出现以下错误:

W/ppbrewery.clim(25370):访问隐藏方法 Landroid/content/Context;->getFeatureId()Ljava/lang/String; (灰名单, 反射,允许)

我对这个问题进行了一些研究,它似乎会这样做,因为我使用的是 API 30。但是,我不知道该怎么做,也不知道如何让它打印我的位置。

查看一些文档:

https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces

底部写着:如何启用对非 SDK 接口的访问?

但是 adb shell settings put global hidden_​​api_policy 1 命令对我没有任何作用。那可能是因为我使用的是 API 30,但我根本不知道。它似乎也没有在 API 29 上做任何事情。

此外,上述解决方案似乎只是针对在开发设备/模拟器上修复它,除非我误解了它。如何修复模拟器和未来的实际部署?

【问题讨论】:

    标签: android flutter dart flutter-dependencies


    【解决方案1】:

    试试这个。

    Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
    Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
    

    您可以通过单击模拟器末尾的三个点来打开此设置

    并且不要忘记像这样在模拟器上设置位置并设置位置。

    【讨论】:

      【解决方案2】:

      获取 Geolocator 的实例,强制 Android Location Manager 并在此调用 getCurrentPosition。通过这种方式,您可以使用 LocationManager 插件代替默认的 FusedLocationProviderClient 插件来检索位置。

      Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
      Position position = await geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.low);
      

      【讨论】:

        【解决方案3】:

        我在 android 模拟器中遇到了同样的问题。在模拟器位置设置中,您必须设置位置,然后在模拟器中打开谷歌地图并找到自己。之后重新启动应用程序就可以了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-10-04
          • 2021-09-15
          • 1970-01-01
          • 1970-01-01
          • 2023-03-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多