ACCESS_FINE_LOCATION permissions update with uses-feature in Ionic mobile application - android

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"

Related

cordova-plugin-scanbot-sdk not working in android 31+

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.

Ionic Cordova InAppBrowser

I have an hybrid app built with:
Ionic 5.4.16
Cordova 10.0.0
AngularCLI 9.0.2
Android sdk 29
I open an URL using Cordova In App Browser https://ionicframework.com/docs/native/in-app-browser .
This URL is a chat page, and in this URL i need access to front and back cameras and microphone, but when I open it, the page doesn't have the access.
It seems it doesn't use the permissions declared in my config.xml, while the app it uses these permissions in its lifecycle.
In my "Android platform" section i declared:
<config-file mode="merge" parent="/*" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
private iab: InAppBrowser
....
const ref = this.iab.create(url, '_blank', 'location=no,zoom=no');
Is there any other permission I need to declare?
Do you have any suggest?

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>

Add android.permission.CAMERA with Cordova

I am using the latest version of Cordova (6.3.1) and I want the following permission to appear in the AndroidManifest.xml :
<uses-permission android:name="android.permission.CAMERA" />
Adding this line by hand does not work because the XML is regenerated each time I run the command cordova run android
I have added the cordova-plugin-camera to my project with
cordova plugin add cordova-plugin-camera
This plugin does NOT add the CAMERA permission in the AndroidManifest.xml
I don't know if this is normal
How can I add this permission to my project ?
Edit :
Usually, Cordova plugins are in charge of adding required permissions into the manifest. The camera plugin does not add this specific permission, I wonder :
if the plugin should add this permission (bug ? I have opened an issue on their Jira tracker)
if I can add this permission by hand myself, maybe in the Cordova's config.xml
I don't think the Camera plugin ever added this permission to AndroidManifest.xml. Looking through the Github repo, WRITE_EXTERNAL_STORAGE was added in June 2013 (CB-3654), but I don't see anything for the camera itself. Not sure why that would be, but you can either add the permission to AndroidManifest.xml yourself or add a config-file directive in your project's config.xml file, for example:
<config-file target="AndroidManifest.xml" parent="/*" mode="merge">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
Are you building native or hybrid app?
For native you can refer this website:
https://developer.android.com/reference/android/hardware/Camera.html

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>

Categories

Resources