[英]How do I add “uses-permissions” tags to AndroidManifest.xml for a Cordova project?
Some <uses-permission>
entries are added automatically to AndroidManifest.xml, based on cordova plugins that you add.根据您添加的cordova 插件,一些<uses-permission>
条目会自动添加到AndroidManifest.xml 中。 However, I need the <uses-permission android:name="android.permission.INTERNET" />
permission, which isn't added automatically.但是,我需要<uses-permission android:name="android.permission.INTERNET" />
权限,该权限不会自动添加。
I can add that directly to AndroidManifest.xml, but it will get overwritten the next time I run cordova build
, and I don't want to have to keep re-adding it...我可以将它直接添加到 AndroidManifest.xml 中,但是下次运行cordova build
时它会被覆盖,而且我不想继续重新添加它...
I'm sure there's a "Cordova" way of specifying permissions (in config.xml, or elsewhere), but I'm not seeing it in their documentation anywhere...我确定有一种“Cordova”方式来指定权限(在 config.xml 或其他地方),但我没有在他们的文档中的任何地方看到它......
So, what is the "Cordova way" of specifying user permissions?那么,指定用户权限的“Cordova 方式”是什么?
As I know AndroidManifest.xml will not be generated every time when you run cordova build
.据我所知,每次运行cordova build
时都不会生成 AndroidManifest.xml 。 When you add/remove a plugin it will be modified accordingly.当您添加/删除插件时,它将相应地进行修改。 But if you add your own permissions it will not be removed(Unless there is a conflict).但是如果你添加自己的权限,它不会被删除(除非有冲突)。
Since the permissions are Android (platform) specific, in your case you have to add it into the AndroidManifest.xml file only.由于权限是 Android(平台)特定的,在您的情况下,您只需将其添加到AndroidManifest.xml文件中。
Even in plugin.xml of any plugin they add permission as shown :即使在任何插件的 plugin.xml 中,他们也会添加权限,如下所示:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
</platform>
Which says add uses-permission line to AndroidManifest.xml file at the installation time of plugin.其中说在插件安装时将 uses-permission 行添加到 AndroidManifest.xml 文件中。 But you cant mention this in config.xml file.但是你不能在 config.xml 文件中提到这一点。
Also don't forget to put this attribute in the root widget element present in the config.xml file,located in the root folder of the app, as @hiddentao said in a comment.另外不要忘记将此属性放在config.xml文件中的根小部件元素中,该文件位于应用程序的根文件夹中,正如@hiddentao 在评论中所说。
config.xml配置文件
<widget
xmlns:android="http://schemas.android.com/apk/res/android"
...>
Cordova (version 8) has built in functionality for this . Cordova(版本 8) 为此.
I was able to add the required 'uses-permission' line to AndroidManifest.xml
using:我能够使用以下方法将所需的“uses-permission”行添加到AndroidManifest.xml
中:
<platform name="android">
...
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</edit-config>
...
</platform>
One can add this plugin ( Git ).可以添加这个插件( Git )。 It makes you capable of defining platform-specific configurations (permissions too) under config.xml file in the following way:它使您能够通过以下方式在 config.xml 文件下定义特定于平台的配置(也包括权限):
<platform name="android">
<custom-config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
<!--<uses-permission android:name="android.permission.NETWORK_ACCESS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
</custom-config-file>
</platform>
Also don't forget to put this attribute in the root widget element as @hiddentao said in a comment.另外不要忘记将此属性放在根小部件元素中,正如@hiddentao 在评论中所说。
xmlns:android="http://schemas.android.com/apk/res/android"
Manually add under config-file tag在 config-file 标签下手动添加
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.