Meteor Cordova: Add Permissions

Hey guys,
how can I add “CAMERA” permission to my Meteor Cordova project? I only know that we have App.setPreference() in mobile-config.js, but that doesn’t allow me to set a permission?

1 Like

For me, it just worked, once I added the Cordova camera plugin. The easiest way to do so is to include mdg:camera.

Yeah, just found that package - but at the moment, I want to use the official Cordova plugin (cordova-plugin-camera) for it and that doesn’t add permission automatically :frowning:

I’d still be interested in a general solution for setting android permissions.

In my case, I’d like to use the web standard Vibration API, available through Crosswalk, which requires explicit permission on Android.

Should it be possible to inject permissions via App.setPreference or App.configurePlugin and if so, how? I tried the following to no avail:

App.configurePlugin('cordova-plugin-crosswalk-webview', {
  XWALK_COMMANDLINE: '--permissions=contacts:geolocation:messaging:vibration'
});

I think it would be nice to be able hook into the cordova build in a more flexible way, or at least add support for passing down permissions explicitly from mobile-config.js. :smiley:

5 Likes

I haven’t tested this, but from the documentation on configuration options for the Crosswalk plugin it seems you may have to use xwalkCommandLine instead of XWALK_COMMANDLINE to set the command line options to pass on. Not sure if that would help however, because this may only work for a stand-alone Crosswalk app as opposed to one using Cordova.

It’s a bit of a hack, but the easiest way to add permissions that are not added automatically by one of the plugins you use is to create an empty plugin and add the permissions to its plugin.xml. I found an example of that usage here.

I agree it would be nice to find a better way to do this, and to make the Cordova build process more flexible in general. That would probably require changes to Cordova however, and is not something we can solve purely from the Meteor side.

1 Like

Thx for your suggestion to use an empty plugin. It’s not ideal but should work :slight_smile:

@martijnwalraven. Thanks for the hint with the empty plugin. Would it also be possible to remove permissions set by other plugins this way?

I am using a plugin that uses

<config-file target="AndroidManifest.xml" parent="/*">
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>

and would like to remove the ACCESS_FINE_LOCATION permission. How can I make sure that removing the permission is done after adding the permission?

Newbie question… how can i use the plugin.xml?

i ended up sung cordova-plugin-diagnotic to ask user permission to access camera and storage… thanks

I think you need to create a local Cordova plugin and add the permissions there and then add this plugin to your Meteor project.

@junskihere how did you manage to get cordova-plugin-diagnositic to work with Meteor? It looks like that only works with Android Cordova 5.0 and up and Meteor does not currently support 5.0

i need cordova permission to access camera,contacts in meteor…plz reach me…

For anyone wondering how to add the plugin to meteor:

  1. Download the plugin.xml file into a folder inside your root project directory. In the example I added it to my packages folder.
  2. Edit plugin.xml adding the permissions you need to be included in your manifest: for example:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> and etc…
  3. Add your edited plugin to your meteor project:
    meteor add cordova:me.dispatch.crosswalk-permissions@file://./packages
2 Likes

Thank you for the tip with the custom plugin, that was a Life-Saver right now… :slight_smile: