2 Replies Latest reply on Sep 6, 2016 6:58 PM by simonwatt

    Override element in plugin config from apps config.xml

    simonwatt

      One of the plugins I use has the following config: https://github.com/katzer/cordova-plugin-local-notifications/blob/master/plugin.xml

       

      One of the sections in there is:

       

      <config-file target="AndroidManifest.xml" parent="/manifest">

                  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

                  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

      </config-file>

       

      I would like to override it to be:

       

      <config-file target="AndroidManifest.xml" parent="/manifest">

                  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

                  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"  android:maxSdkVersion="18" />

      </config-file>

       

      This is because I understand that as of KitKat (4.4) permissions are not required to write to the external storage of your app (https://developer.android.com/guide/topics/data/data-storage.html#AccessingExtFiles), and I feel like requesting this permission is putting off users from downloading the app.

       

      I'm building my app using PhoneGap Build (phonegap-version is cli-6.3.0), is there a way to this from my apps config.xml? So far the several things I've tried have resulted in errors about malformed config or duplicate <uses-permission> elements.

       

      Thanks

        • 1. Re: Override element in plugin config from apps config.xml
          ryanskihead Adobe Employee

          Here's a few possibilities:

           

          1. Fork the plugin and modify as desired, and build from your fork (see the docs for using plugins from git repos: Plugins | PhoneGap Docs).
          2. Fork the plugin, modify, and send a pull request to have it updated on the npm repo (or both 1 and 2).
          3. Try using PGB's config-file element to modify the manifest: Modifying Manifests | PhoneGap Docs  (not sure if it will work in this use case).
          • 2. Re: Override element in plugin config from apps config.xml
            simonwatt Level 1

            I had previously tried with the config-file element with no success, but I had missed the documentation on the 'mode' attribute, which I think has made the difference. I've now resolved my issue, the plugin is still working and it's no longer requesting storage access on Android 4.4 plus. Thanks!

             

            This did the trick:

             

                <platform name="android">

                    <config-file target="AndroidManifest.xml" parent="/manifest" mode="merge">

                        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"  android:maxSdkVersion="18" />

                    </config-file>

                </platform>

             

            (For anyone reading this, also make sure you have included the android namespace on the widget element).