Felipe Plets
Felipe Plets

Reputation: 7510

Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app?

I'm working on a Cordova app for Android, this app must upload an image from the device. The tests are being performed on a Motorola Xoom Tablet with Android 4.0.4.
The Cordova version is 2.7.0.

The app opens and the ondeviceready is properly called.

The user press a button and the following function is triggered:

capture: function(sourceType) {
  navigator.camera.getPicture(this.onCaptureSuccess, this.onCaptureFail, {
    quality: 20
    ,targetWidth: 100
    ,targetHeight: 100
    ,destinationType: Camera.DestinationType.FILE_URI 
    ,sourceType: Camera.PictureSourceType.PHOTOLIBRARY
    ,correctOrientation: false
  });
}

Once the function is triggered an menu is shown with 4 options to choose the source of the file (ASTRO File Manager, ES File Explorer, Files and Gallery) and the following messages are added to the Logcat:

05-11 13:30:51.400: D/DroidGap(11102): Paused the application!
05-11 13:30:51.400: D/CordovaWebView(11102): Handle the pause

I can choose any of the four and the LogCat shows the following messages:

05-11 13:33:57.960: D/DroidGap(11409): onDestroy()
05-11 13:33:57.960: D/CordovaWebView(11409): >>> loadUrl(javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};)
05-11 13:33:57.960: D/PluginManager(11409): init()
05-11 13:33:57.970: D/CordovaWebView(11409): >>> loadUrlNow()
05-11 13:33:58.120: D/OpenGLRenderer(11409): Flushing caches (mode 0)
05-11 13:33:58.350: D/OpenGLRenderer(11409): Flushing caches (mode 1)

Once I choose the image I want to upload the app shows a message "Unfurtunately, the process .. has stopped." and show the following LogCat messages:

05-11 13:40:06.750: D/DroidGap(11886): DroidGap.onCreate()
05-11 13:40:06.770: D/CordovaWebView(11886): CordovaWebView is running on device made by: Motorola
05-11 13:40:06.770: D/JsMessageQueue(11886): Set native->JS mode to 2
05-11 13:40:06.770: D/DroidGap(11886): DroidGap.init()
05-11 13:40:06.770: D/CordovaWebView(11886): >>> loadUrl(file:///android_asset/www/index.html)
05-11 13:40:06.770: D/PluginManager(11886): init()
05-11 13:40:06.780: D/CordovaWebView(11886): >>> loadUrlNow()
05-11 13:40:06.780: D/DroidGap(11886): Incoming Result
05-11 13:40:06.780: D/DroidGap(11886): Request code = 18
05-11 13:40:06.780: D/DroidGap(11886): We have a callback to send this result to
05-11 13:40:06.780: D/AndroidRuntime(11886): Shutting down VM
05-11 13:40:06.780: W/dalvikvm(11886): threadid=1: thread exiting with uncaught exception (group=0x40a2f1f8)
05-11 13:40:06.800: E/AndroidRuntime(11886): FATAL EXCEPTION: main
05-11 13:40:06.800: E/AndroidRuntime(11886): java.lang.RuntimeException: Unable to resume activity {com.ubihealth/com.ubihealth.UbiHealth}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=18, result=-1, data=Intent { dat=content://media/external/images/media/7468 }} to activity {com.ubihealth/com.ubihealth.UbiHealth}: java.lang.NullPointerException
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2466)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2494)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2008)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1169)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.os.Looper.loop(Looper.java:137)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.main(ActivityThread.java:4446)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at java.lang.reflect.Method.invokeNative(Native Method)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at java.lang.reflect.Method.invoke(Method.java:511)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at dalvik.system.NativeStart.main(Native Method)
05-11 13:40:06.800: E/AndroidRuntime(11886): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=18, result=-1, data=Intent { dat=content://media/external/images/media/7468 }} to activity {com.ubihealth/com.ubihealth.UbiHealth}: java.lang.NullPointerException
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3002)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2453)
05-11 13:40:06.800: E/AndroidRuntime(11886):    ... 12 more
05-11 13:40:06.800: E/AndroidRuntime(11886): Caused by: java.lang.NullPointerException
05-11 13:40:06.800: E/AndroidRuntime(11886):    at org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:858)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.Activity.dispatchActivityResult(Activity.java:4649)
05-11 13:40:06.800: E/AndroidRuntime(11886):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2998)
05-11 13:40:06.800: E/AndroidRuntime(11886):    ... 13 more
05-11 13:40:07.040: D/chromium(11886): Unknown chromium error: -6
05-11 13:40:07.070: D/CordovaNetworkManager(11886): Connection Type: none

Any idea on what can be my error?

Update: I've updated the project I had with Cordova 2.6.0 and tried the code above and it not worked. Now I've created a new project with Cordova 2.7.0 and just copied the Cordova code from the old project and it worked fine.

Upvotes: 2

Views: 942

Answers (1)

MBillau
MBillau

Reputation: 5376

I tested this code with Cordova 2.7 on a few devices and have the following results:

Nexus 7 (4.2)                     no problems
HTC Sensation (2.3.4)             no problems
HTC Evo 4g (2.2)                  no problems
Samsung Galaxy Tab 7.0 (4.0.4)    Had the below Java error but JS seems to get the image

(4.0.2 - 05-15 15:16:53.895: E/ActivityThread(3520): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@4131a248 that was originally registered here. Are you missing a call to unregisterReceiver()?

Will test on a Xoom tablet when my coworker gets back from lunch.

Upvotes: 1

Related Questions