How to add GeoLocation-Permissions in config.xml - android

I'd like to set androids permissions to use geolocation in config.xml.
I don't want to use cordova-plugin-geolocation which would set these settings as a side-effect because the webviews I am targeting (crosswalk) support GeoLocation out of the box. The Plugin would just be bloatware.
I don't want to write it directly in AndroidManifest.xml because I am using cordova prepare to prevent having any plattform-specific stuff inside my repository. Everybody is currently able to build the plattforms from scratch without any plattform-specific stuff from our git-repo.
What I tried
I took a look at cordova-plugin-geolocation to see how they would achieve this.
<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" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
</config-file>
</platform>
This returns the following in my build-phase
Error: Command failed: /bin/sh -c cordova build android
/Users/sven/.../cordova/platforms/android/build/intermediates/res/armv7/debug/xml/config.xml:34: error: Error parsing XML: unbound prefix
What my next step would be
I am unsure about why the 'rob-from-cordova-plugin-geolocation'-approach does not work, but maybe it would help to just put above into a new plugin? Is it worth a try?

Your error is "unbound prefix", have you provided a definition for the "android" prefix that you're using in "android:name"?
Looking at cordova-plugin-geolocation plugin.xml you may need to add this to your XML:
xmlns:android="http://schemas.android.com/apk/res/android"
So that the android namespace is defined.

You will be able to add permissions (and many other extra configuration actions) in Cordova straight from CLI's config.xml by adding the plugin cordova-custom-config to your environment. It will add nothing in your application and consists only in a group of Cordova hooks.
So, only add the XML chuck in your config.xml (<config-file...), and also add what #SimonPrickett say in his answer.

Related

Getting internet permission in flutter app

I'm new to flutter and I'm in a situation to get internet permission for our flutter app which we are developing, we've used enter link description here for handling permissions. We also accessed microphone permission and it worked well. but can't get the internet permission request.
And I want to know whether internet permission(But I've mentioned in the Manifest.xml file) is not mandatory or not?
just write this in your Anroidmanifest.xml in android module in flutter project:
<uses-permission android:name="android.permission.INTERNET" />
Internet permissions are required for macOS in addition to Android so I'm adding an expanded answer.
Android
Add the following line in your AndroidManifest.xml file before the <application> section:
<uses-permission android:name="android.permission.INTERNET" />
See also the Flutter docs for creating an Android release.
macOS
Add the following key-value pair to macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements:
<key>com.apple.security.network.client</key>
<true/>
See also the Desktop support for Flutter documentation.
It can be a better solution . Paste the code below to android manifest.xml
uses-permission android:name="android.permission.INTERNET" /
uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
Right-Click info.plist and Open As -> Source Code. This will open the file in XML format.
Add the following to the bottom of the info.plist xml file.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>

Cordova plugin add fails for ENOENT on AndroidManifest

I've developed a custom plugin for a cordova application and trying to test it out with the latest cordova Android platform version.
Whenever I run:
cordova plugin add ../my-plugin
cordova platform add android
or
cordova platform add android
cordova plugin add ../my-plugin
I get the following error:
Failed to install 'com.my.plugin': Error: ENOENT: no such file or directory, open '/path/to/project/my-application/platforms/android/AndroidManifest.xml'
This is the content of my plugin.xml file for what concerns the AndroidManifest.xml.
<config-file target="app/src/main/AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</config-file>
I've already seen this answer which is pretty commonly shared throughout different resources and websites I visited but is not helping me since I'm already using app/src/main/AndroidManifest.xml after updating from android#6.4.0 to android#7.0.0.
My environment is:
macOS
cordova#8.1.2
android#7.1.1
Note: As of now I made it work by using android#6.4.0 but I'd like to understand how to make it work with newer platform versions.

Debug Ionic application with android:debuggable="false"

A have installed my Ionic application on real device. The app is released, signed and has android:debuggable="false".
I faced some problems on that specific device and I need to debug it (not to create and install new --debug build).
Is there some way to debug it? To "attach" it somehow to a keystore to be authorised, or something else...? Any ideas?
I am still trying to find a better way, but so far I am able to debug my Ionic app (a signed --release build) running on a real device via the Chrome (desktop) console, by specifying:
<application android:debuggable="true">
directly in the AndroidManifest.xml file. The attribute in not overwritten when I build the project with the Ionic CLI.
What I would prefer is to set the attribute from the config.xml file, so I don't have to add it again manually in AndroidManifest.xml when I remove/add the platform.
You can add this in your config.xml to solve it.
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</edit-config>
Then, you can debug in Chrome.
I've just faced a similar issue (I wanted to create a debuggable Cordova app with cordova build android --release) and I've also wanted to add something to the Cordova config.xml instead of directly editing AndroidManifest.xml, which is generally a bad idea.
The following piece of code worked for me on Cordova 8.1.2, Cordova Android platform version 7.1.4. Just put this inside your config.xml file (somewhere inside the widget tag) and you should be good to go:
<config-file mode="merge" parent="/manifest" platform="android" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</config-file>
This will also cause the :app:lintVitalRelease linter to give you a [HardcodedDebugMode] error (and for good reason), but the APK will build fine regardless.

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 to edit AndroidManifest.xml in PhoneGap 3

It seems PhoneGap generates that file automatically when config.xml is modified.
I wish to add Ad network's activities, services, etc in AndroidManifest.xml but I can't find the correct way to edit that file.
Phonegap uses config.xml to create androidmanifest.xml when you add the android platform to a project.
It is also modified when you add plugins and build the project (for example, it adds the required permission for the plugin).
But you can also manually edit the file in platforms/android/AndroidManifest.xml to add permissions, configure the activity or the application... it will not be lost when you rebuild your project.
Typically this is found in the "res" directory ( - src - gen [Generated Java Files] - Android - Android Dependencies - Referenced Libraries - assets - bin - libs - res - AndroidManifest.xml - proguard-project.txt - project.properties) of course this is depending on what version of Cordova you are using. Typically most of these things are specified in the config.xml for newer Phonegap builds from my understanding which is why you don't need to include an AndroidManifest.xml file when using Phonegap Build. I would recommend trying Configap to edit the main config.xml and see if any of the settings/services you need to access are options. Configap can be found here!
forgot to mention I use Notepad++ to edit my .xml on the fly but you can also open in the sdk
You probably want to check out cordova-custom-config.
It supports many extra settings in the cordova config.xml to customise the AndroidManifest.xml.
I'm using it to change the android:configChanges setting (adding uiMode to stop it from reloading when docking/undocking) and it works great.
The cordova-custom-config github page shows a full example with all supported options so it's very easy to setup.
Nowadays in Cordova, we can use <config-file> and <edit-config> in our config.xml to make simple custom changes to AndroidManifest.xml.
Examples copied from the docs:
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.foo.Foo" android:label="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
</config-file>
<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
<uses-sdk android:minSdkVersion="16" android:maxSdkVersion="23" />
</edit-config>
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[#android:name='MainActivity']" mode="overwrite">
<activity android:name="MainActivity" android:label="NewLabel" android:configChanges="orientation|keyboardHidden" />
</edit-config>
Note: to use the android: namespace in your config.xml, you need to add xmlns:android="http://schemas.android.com/apk/res/android" to the root <widget> element.

Categories

Resources