How do I add “uses-permissions” tags to AndroidManifest.xml for a Cordova project?

前端 未结 4 1289
鱼传尺愫
鱼传尺愫 2020-12-13 05:05

Some entries are added automatically to AndroidManifest.xml, based on cordova plugins that you add. However, I need the

相关标签:
4条回答
  • 2020-12-13 05:06

    Manually add under config-file tag

     <config-file target="AndroidManifest.xml" parent="/manifest">
        <uses-permission android:name="android.permission.INTERNET"/>
    </config-file>
    
    0 讨论(0)
  • 2020-12-13 05:13

    Cordova (version 8) has built in functionality for this.

    I was able to add the required 'uses-permission' line to AndroidManifest.xml using:

    <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>
    
    0 讨论(0)
  • 2020-12-13 05:17

    One can add this plugin (Git). It makes you capable of defining platform-specific configurations (permissions too) under config.xml file in the following way:

    <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.

    xmlns:android="http://schemas.android.com/apk/res/android"
    
    0 讨论(0)
  • 2020-12-13 05:20

    As I know AndroidManifest.xml will not be generated every time when you run cordova build. 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.

    Even in plugin.xml of any plugin they add permission as shown :

    <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. But you cant mention this in config.xml file.

    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

    <widget
      xmlns:android="http://schemas.android.com/apk/res/android"
      ...>
    
    0 讨论(0)
提交回复
热议问题