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>
Related
I can't get the cordova-plugin-scanbot-sdk plugin to work with release builds (it works if I build in debug mode), all my plugins are with the latest version, my cordova and cordova android are also up to date.
I can use the camera and filesystem in the app without any problems, but if I try to use the scanbot the app stays on this screen but doesn't ask the user for permission to use the camera. I also tried to add the camera permission manually in config.xml using:
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</edit-config>
but it didn't work.
Here is a screenshot of what I see when I try to open the plugin.
I'm developing an app with ionic and cordova. when i'm done building and i do ionic cordova prepare android and i go to android studio to deploy on the phone i get camera duplications in Androidmanifest.xml and i have to manually clean it up to allow a successful deployment.
Android.manifest after ionic cordova prepare android
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
What i want to achieve is to configure the config.xml so that it doesn't happen that i'd always have to clean the camera duplicate in Androidmanifest.xml
after manually cleaning which makes it work
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
I tried this in config.xml but it didn't work
<edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[#android:name='android.hardware.camera']">
<uses-feature android:name="android.hardware.camera" />
</edit-config>
Try using cordova-custom-config.
ionic cordova plugin add cordova-custom-config
config.xml:
<platform name="android">
....
<custom-preference delete="true" name="android-manifest/uses-feature[#android:name='android.hardware.camera']" />
</platform>
Then remove and add your android platform:
ionic cordova platform rm android
ionic cordova platform add android#your_version
I think the best way to solve this is to find out why those contradicting uses-feature's are added in the first place and remove them there.
I'd also try the solution SidiBecker suggested, because it is quite elegant.
However, if that doesn't work, you can remove code from your android manifest programatically with an after_prepare hook, the same way as I suggested in this answer: use config.xml to control how plugins are installed
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"
I'm extending an ios app to the android platform - I'm unfamiliar with the android tools but following the tuts.
I have added the platform but when I run the 'cordova build android' I get errors on the AndroidManifest.xml
When I trace this it seems that lines are being added in the uses-permission section (see the last 3) that have no android namespace
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission name="android.permission.READ_PHONE_STATE" />
if I add the namespace and rebuild, the error becomes one of duplication. If I delete the offending lines, then the rebuild just re-writes them.
The ios version of my app works perfecto, so I'm assuming its something to do with how the plugins write to this file on android build.
Before I start to debug by unpicking the plugins, has anyone else been here before and resolved it, and are hungry for upvotes?
I am afraid you need to setup the issue manually as that is not resolved yet, its still alive.
You have to open your plugins/android.json and remove the duplicate keys in there. In your case search for WRITE_EXTERNAL_STORAGE, MODIFY_AUDIO_SETTINGS, READ_PHONE_STATE in android.json and remove the duplicates.
Then open up platforms/android/AndroidManifest.xml and remove the duplicate <uses-permission... /> tags. And then rebuild and try again.
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>