1

I'm developing an app using Phonegap Build that needs to take pictures or select one from the gallery. First I'm developing the Android version, but I'm going to need to develope it also for iOS.

I saw a lot of examples around the web (and in the phonegap documentation), but none of them worked for me. First of all, I found four different ways to add the Camera plugin to the config.xml in a lot of different posts:

1:

<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />

2:

<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>

3:

<feature name="Camera">
    <param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
    <param name="ios-package" value="CDVCamera" />
</feature>

4:

<gap:plugin name="org.apache.cordova.camera" />
<gap:plugin name="org.apache.cordova.media-capture" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.media" />
<gap:plugin name="org.apache.cordova.device" />

The option number 2 is the only one that worked for me, and I'm saying this because is the only one that after I've generated the APK and try to install in a device (Tried on a Samsung S4 and on a Nexus 7 tablet), it asks for permitions to take pictures and videos and read, modify and delete content of the USB storage. The others, don't. (I also tried different combinations of more than one of this options, even all of them at the same time).


By the way I'm using the current version of Phonegap that the Build at this time (28 apr 2015) states that is 3.7 (I also tried forcing version 3.3 but saw no difference).

I tried several codes inside my app, I'm not going to write all the examples down here because I think it makes not point because they're all the same at the root (navigator.camera.getPicture), for example: navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50 });

Well, the "navigator.camera.getPicture" always send me the same error after a Try-catch: Camera is not defined.


I've included the phonegap.js (not the file but the reference in the html) as stated in Phonegap Build Documentation by adding:

<script src="phonegap.js"></script>

and also tried with:

<script src="cordova.js"></script>

Also tried not including any reference to the phonegap API. (Just in case?!)


It has been 4 days searching and trying different things, if anybody has any clue, it would be greatly appreciated.

Thanks, and sorry for my english.

///////////////////////////////////////////////////////////////////////////////

RESOLUTION:

It had to be a problem with the Phonegap Build Server. Because at the moment I wrote this post I was trying to compile the app without success because of the server was down, so I started working with other things. Today I've recompiled the app, without modifing anything and now it works (The camera). By the way I went with option nº4, don't know if the other ones work.

Jorge Lizaso
  • 199
  • 1
  • 3
  • 15
  • Can you verify the camera was installed using `cordova plugin add cordova-plugin-camera`? That should automatically setup your config.xml file. `cordova plugin list` will show you all the plugins that were installed. My next guess would be you are not waiting for the `deviceready` event. – laughingpine Apr 28 '15 at 18:58
  • First of all thanks for your comment. I'm not using the Cordoba CLI, I'm developing the app with Dreamweaver, and uploading a zip with all the project to Phonegap Build (build.phonegap.com). And yes, I'm wainting for the deviceready event. – Jorge Lizaso Apr 28 '15 at 19:39
  • Then my guess is the plugin isn't getting copied over at build time properly. The build process should run a `cordova prepare`, which copies over the plugins to the platform. Since you appear to be developing for Android, there should be a file structure like `platforms/android/src/org/.../camera/CameraLauncher.java` The js files should be listed under `assets/www/plugins`. If those are missing, then you probably have installed the plugin incorrectly . Installing plugins manually is a pain, but doable. I would really recommend getting the CLI working to improve your workflow. – laughingpine Apr 28 '15 at 20:47
  • Finally it starts working, It had to be a problem of the phonegap build server, because I started working with another segment of the app and didn't change anything from the config.xml since my last try, and compile it today and it is working now. Option number 4 at least. Don't know if the other ones also works. Thank you for your advices. – Jorge Lizaso May 01 '15 at 21:08

0 Answers0