Add android.permission.CAMERA with Cordova
Asked Answered
P

3

11

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
Personal answered 25/8, 2016 at 14:44 Comment(6)
do you any error in console ?Krystalkrystalle
No error in console. The permission is just not present in the manifest.Personal
Please remove and reinstall your camera plugin.Then check your manifist file .ThanksKrystalkrystalle
@HassanALi I just tried that and the CAMERA permission did not appear in the manifest :(Personal
if you manually add this permission ,Isn't it works ?Krystalkrystalle
Just tell me how to add it. As I say in my question, if I add the permission directly in the manifest, it goes away when I build my app, because the build command overwrites the manifest file.Personal
G
17

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>
Galliwasp answered 14/12, 2016 at 21:46 Comment(1)
I had to add xmlns:android="http://schemas.android.com/apk/res/android" to the root widget tag in the config.xml to get it work.Algerian
K
0

Regarding this challenge. I also faced the same problem recently. Thanks Johann for your innovative suggestion of adding the xmlns:android="http://schemas.android.com/apk/res/android" to the root widget tag in the config.xml

Then also, reading the docs on the android developer website, it is obvious that the
<uses-feature android:name="android.hardware.camera" /> doesn't work on recent versions of andriod API levels less than API 21. So, to make this work on newer version of Android, you have to use <uses-feature android:name="android.hardware.camera2" /> which is a reference to the deprecated camera class.

you can add this lines to your AndroidMainfest.xlm file or update your config file directive to use this.

 <widget xmlns:android="http://schemas.android.com/apk/res/android">
 <config-file target="AndroidManifest.xml" parent="/*" mode="merge">
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera2" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
</config-file>
Kesley answered 21/7, 2024 at 10:33 Comment(0)
S
-10

Are you building native or hybrid app?

For native you can refer this website:

https://developer.android.com/reference/android/hardware/Camera.html

Spectrophotometer answered 25/8, 2016 at 14:57 Comment(2)
Cordova is a tool to build hybrid app, I am using Cordova CLI to build my appPersonal
FYI: it is framework and if you need to change permission for android you can do that in config file.Spectrophotometer

© 2022 - 2025 — McMap. All rights reserved.