Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-6875

navigator.camera.getPicture throws exception and crashes app on Android

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.4.0
    • None
    • cordova-plugin-camera
    • Android 4.1.2, HTC Desire 500 (without SDCard!)

    Description

      On one of our test devices (HTC Desire 500 with Android 4.1.2) our app crashes when getting a picture from the camera. As wedgberto describes: the exception will be thrown if no SD card is mounted. But the camera app stores the photo and you can get it later from the photo album. (please see https://issues.apache.org/jira/browse/CB-5133?focusedCommentId=13874707&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13874707)

      The HTC throws an IllegealStateException in

      CameraLauncher.java#getUriFromMediaStore()
      try {
                  uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
              } catch (UnsupportedOperationException e) {
      // ...
      }
      // ...
      

      The IllegalStateException won't be catched and the app will be killed:

      06-04 10:56:43.800: E/JHEAD(2816): can't open '/data/data/com.example.package/cache/.Pic.jpg'
      06-04 10:56:43.830: W/dalvikvm(2816): threadid=1: thread exiting with uncaught exception (group=0x40cc7600)
      06-04 10:56:43.850: E/AndroidRuntime(2816): FATAL EXCEPTION: main
      06-04 10:56:43.850: E/AndroidRuntime(2816): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=null} to activity {com.example.package/com.example.package.Finanzchecker}: java.lang.IllegalStateException: Unable to create new file: /storage/sdcard0/DCIM/Camera/1401872203812.jpg
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:3660)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:3710)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread.access$1100(ActivityThread.java:151)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.os.Handler.dispatchMessage(Handler.java:99)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.os.Looper.loop(Looper.java:155)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread.main(ActivityThread.java:5536)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at java.lang.reflect.Method.invokeNative(Native Method)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at java.lang.reflect.Method.invoke(Method.java:511)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at dalvik.system.NativeStart.main(Native Method)
      06-04 10:56:43.850: E/AndroidRuntime(2816): Caused by: java.lang.IllegalStateException: Unable to create new file: /storage/sdcard0/DCIM/Camera/1401872203812.jpg
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.os.Parcel.readException(Parcel.java:1442)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.content.ContentProviderProxy.insert(ContentProviderNative.java:482)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.content.ContentResolver.insert(ContentResolver.java:874)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at org.apache.cordova.camera.CameraLauncher.getUriFromMediaStore(CameraLauncher.java:737)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at org.apache.cordova.camera.CameraLauncher.processResultFromCamera(CameraLauncher.java:382)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at org.apache.cordova.camera.CameraLauncher.onActivityResult(CameraLauncher.java:624)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:897)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.Activity.dispatchActivityResult(Activity.java:5275)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:3656)
      06-04 10:56:43.850: E/AndroidRuntime(2816): 	... 11 more
      06-04 11:01:43.940: D/Process(2816): killProcess, pid=2816
      

      We've catched RuntimeExcpetion instead of UnsupportedOperationException to catch also the IllegalStateException and got a follow up NullPointerException in processResultFromCamera(CameraLauncher.java:384) from FileHelper.getRealPath(FileHelper.java:80). After fixing this too, the app won't be killed anymore.

      We've tested also other apps (like the twitter app) which can't get the photo from the camera too. But they won't crash/be killed.

      I've created a pull request: https://github.com/apache/cordova-plugin-camera/pull/29

      Attachments

        Activity

          People

            Unassigned Unassigned
            dombn Dominik Pesch
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: