How to add permissions to Android PhoneGap project? - android

A plugin I am using to access the AccountManager in android through phonegap requires some permissions. I am using PhoneGap 3.4.0. In the config.xml in my www folder there is a tag
<preference name="permissions" value="none"/>
I am having the hardest time figuring out how I add permissions to this config.xml file. All the other questions I've found say to alter the manifest file, but that feels wrong with me setting so many things in this config.xml file.
How do I add the permissions in the config.xml file? Comma separated list in the tag referenced above?
Here are the permissions I have added to my manifest file:
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

Please check you have declared the following.
<feature name="NetworkStatus">
<param name="android-package" value="CDVConnection" />
</feature>
Network status will be the feature name and value will be your class name.
In Android Manifest,
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Aso check cordova_plugin.js
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [{
"file": "plugins/org.apache.cordova.dialogs/www/notification.js",
"id": "org.apache.cordova.dialogs.notification",
"merges": ["navigator.notification"]
}, {
"file": "plugins/org.apache.cordova.network-information/www/network.js",
"id": "org.apache.cordova.network-information.network",
"clobbers": ["navigator.connection", "navigator.network.connection"]
}];
module.exports.metadata = // TOP OF METADATA
{
"org.apache.cordova.device": "0.2.8",
"org.apache.cordova.network-information": "0.2.7"
}
});
These are some permission types.
Thanks.

Related

Cordova Camera permission missing in Manifest file

I have a cordova app using version 6.4.0. I am building using phone gap build service by uploading zip file.
I have following permissions defined in config file:
<platform name="android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</platform>
After build, Android manifest file is missing Camera permission. Rest of the permissions are added to manifest file.
Is Camera permission required in manifest file or other permissions shown above are sufficient for camera permissions?
You don't need to edit your config.xml file at all for this, nor for using any other plugin for the matter.
When installing the Camera plugin and during build time, Cordova will automatically edit your AndroidManifest based on the plugin's plugin.xml file settings to add all required permissions for you.
And do NOT edit a plugin's XML file either unless you are absolutely sure what you are doing, 99% of the time those files shouldn't be tweaked.
Use this code in config.xml
for the camera access, u need this only.remove all other permissions
<plugin name="cordova-plugin-camera" spec="2.4.1" />
<plugin name="cordova-plugin-media-capture" source="npm" spec="1.4.1" >
<variable name="CAMERA_USAGE_DESCRIPTION" value="App would like to access the camera." />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App would like to access the library." />
</plugin>

How to specify user-permission in Ionic source code

I need two permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
So far, what I did: I modified platforms\android\AndroidManifest.xml file manually (in Ionic project) and added this two lines, but this file and whole platforms folder are not under source control. As a result, with each clean checkout, these permissions are missing.
Is there a way to specify these two permissions somewhere in Ionic configuration that is in git?
You can use following lines in config.xml
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher" />
</feature>
Can Refer below link
https://cordova.apache.org/docs/en/3.0.0/cordova/camera/camera.html

ACCESS_FINE_LOCATION permissions update with uses-feature in Ionic mobile application

I recently received a notification from Google asking to update the way we declare the use of native geolocation in-app.
In Ionic (v1), cordova-plugin-geolocation 2.3.0 "Geolocation" installed.
Line declared in AndroidManifest.xml :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Google is telling us to use instead :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
Is there any clean way to insert it into the AndroidManifest.xml ?
Should it be with a hook ?
Should I wait cordova-plugin-geolocation to update the plugin in order to satisfy Google recommandations ?
The cordova-plugin-geolocation plugin has now been updated so updating to version 2.4.0 should include this requirement.
You can specify android manifest properties from the config.xml file like this:
<platform name="android">
<config-file target="AndroidManifest.xml">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" android:required="false">
</config-file>
</platform>
Also if you are getting the unbound prefix's error, put xmlns:android="http://schemas.android.com/apk/res/android" at the top of your config.xml file
For example:
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
xmlns:android = "http://schemas.android.com/apk/res/android"
id = "com.akis.android"
version = "0.1"

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. However, I need the <uses-permission android:name="android.permission.INTERNET" /> permission, which isn't added automatically.
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...
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...
So, what is the "Cordova way" of specifying user permissions?
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"
...>
Cordova (version 8) has built in functionality for this.
I was able to add the required 'uses-permission' line to AndroidManifest.xml using the following in config.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).
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"
Manually add under config-file tag
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>

Phonegap build with android geolocation

I'm writting an android and iphone app using phonegap 3.0.
So far I have been only compiling the apps remotely using phonegap build.
Now I'm trying to add the geolocation plugin to my app, and in iphone was easy, since I only had to modify the config.xml file.
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
So far so good, the problem was that when adding geolocation to android, the documentation indicates that I have set the following configuration:
(in app/res/xml/config.xml)
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
(in app/AndroidManifest.xml)
<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" />
But I don't have an AndroidManifest.xml file. I could generate the complete android app using:
cordoba platform add android
But I'm not sure if this is what I should do.
Is is what I should be doing? or there is a way to add geolocation without generating the entire android project?
I am a bit confused because you say you are using phonegap 3.0 and you also mention phonegap-build (highest is 2.9). If you are in fact using phonegap-build, the only thing you need is in your config.xml:
<feature name="http://api.phonegap.com/1.0/geolocation"/>
I had the same problem. My geolocation worked on IOS but not on Android. So I Added to config.xml
<feature name="http://api.phonegap.com/1.0/geolocation"/>
As explained by Dom.This was not sufficient. I wanted to share what I did step by step because I lost about 18h of dev time looking for the solution.
This however did not reslove the problem. So I added the plugin using my IDE.
This added the following to the config:
<plugin name="cordova-plugin-geolocation" version="2.2.0" />
I then went inside the plugin.xml under the plugin directorty.
And looked if the following was added.
<!-- android -->
<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" />
</config-file>
...
It was, so I rebooted the device. (on the Ionic forum they say, it might help)
When reinstalling the app I checked for the permission. And it was added. So for the bad Q of the last pic but I took a pic with my cam for it. Hope this helps

Categories

Resources