简体   繁体   English

如何在config.xml中添加GeoLocation-Permissions

[英]How to add GeoLocation-Permissions in config.xml

I'd like to set androids permissions to use geolocation in config.xml. 我想将androids权限设置为在config.xml中使用地理位置。

I don't want to use cordova-plugin-geolocation which would set these settings as a side-effect because the webviews I am targeting (crosswalk) support GeoLocation out of the box. 我不想使用cordova-plugin-geolocation将这些设置设置为副作用,因为我定位(人行横道)的Web视图支持开箱即用的GeoLocation。 The Plugin would just be bloatware. 该插件将只是膨胀软件。

I don't want to write it directly in AndroidManifest.xml because I am using cordova prepare to prevent having any plattform-specific stuff inside my repository. 我不想直接在AndroidManifest.xml中编写它,因为我正在使用cordova prepare防止在我的存储库中包含任何平台特定的内容。 Everybody is currently able to build the plattforms from scratch without any plattform-specific stuff from our git-repo. 目前,每个人都可以从头开始构建平台,而无需我们的git-repo提供任何平台特定的东西。

What I tried 我尝试了什么

I took a look at cordova-plugin-geolocation to see how they would achieve this. 我看了一下cordova-plugin-geolocation,看他们如何实现这一目标。

<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/*">
      <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_LOCATION_EXTRA_COMMANDS" />
    </config-file>
</platform>

This returns the following in my build-phase 这将在我的构建阶段返回以下内容

Error: Command failed: /bin/sh -c cordova build android
/Users/sven/.../cordova/platforms/android/build/intermediates/res/armv7/debug/xml/config.xml:34: error: Error parsing XML: unbound prefix

What my next step would be 我下一步将是什么

I am unsure about why the 'rob-from-cordova-plugin-geolocation'-approach does not work, but maybe it would help to just put above into a new plugin? 我不确定为什么'rob-from-cordova-plugin-geolocation'方法无法正常工作,但是将其放入新的插件中可能会有所帮助? Is it worth a try? 值得一试吗?

Your error is "unbound prefix", have you provided a definition for the "android" prefix that you're using in "android:name"? 您的错误是“未绑定前缀”,是否为“ android:name”中使用的“ android”前缀提供了定义?

Looking at cordova-plugin-geolocation plugin.xml you may need to add this to your XML: 查看cordova-plugin-geolocation plugin.xml,您可能需要将其添加到XML:

xmlns:android="http://schemas.android.com/apk/res/android"

So that the android namespace is defined. 这样就定义了android名称空间。

You will be able to add permissions (and many other extra configuration actions) in Cordova straight from CLI's config.xml by adding the plugin cordova-custom-config to your environment. 通过将插件cordova-custom-config到您的环境中,您将能够直接从CLI的config.xml中在Cordova中添加权限(以及许多其他额外的配置操作)。 It will add nothing in your application and consists only in a group of Cordova hooks. 它不会在您的应用程序中添加任何内容,仅包含一组Cordova挂钩。

So, only add the XML chuck in your config.xml ( <config-file... ), and also add what @SimonPrickett say in his answer. 因此,仅在您的config.xml添加XML卡盘( <config-file... ),并在其答案中添加@SimonPrickett所说的内容。

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

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