ERROR: Camera is being used after Camera.release() was called

N Nicolas Hinze 3 years 7 months ago
28 1 0

I'm having issues using the camera in my Android app after upgrading to Rhomobile 5.4 and the new Camera API.

I'm using:
- Rhomobile 5.4
- minSDK 21
- Android SDK 5.1.1
- Android NDK 10e
- Java 7 u80 SDK
- On OS X

Controller code:

def take_a_picture
    Rho::Camera.desiredWidth = 1280
    Rho::Camera.desiredHeight = 1280
    Rho::Camera.flashMode = "auto"
    Rho::Camera.enableEditing = false
    Rho::Camera.takePicture({}, url_for(:action => :camera_callback_new))
end

  def camera_callback_new
    if @params['status'] == 'ok'
      WebView.execute_js("camera_callback_new('" + Rho::Application.expandDatabaseBlobFilePath(@params["imageUri"]) + "','" + @params['imageUri'] + "');")
    elsif @params['status'] == 'error'
      alertSettings = Hash.new
      alertSettings['message'] = @params.to_s
      alertSettings['title'] = Localization::Fence_controller[:camera_error]
      alertSettings['buttons'] = [Localization::Fence_controller[:ok]]
      alertSettings['type'] = [Rho::Notification::TYPE_DIALOG]
      Rho::Notification.showPopup(alertSettings)
    end
   
    render :back => 'callback:' + url_for(:action => :donothing)
  end

Error message on Android 5.1.1 phone:

E 03/21/2016 10:29:49:164 000007d1 CameraObject| Camera is being used after Camera.release() was called
java.lang.RuntimeException: Camera is being used after Camera.release() was called
at android.hardware.Camera._stopPreview(Native Method)
at android.hardware.Camera.stopPreview(Camera.java:730)
at com.rho.camera.CameraObject.stopPreview(CameraObject.java:435)
at com.rho.camera.CameraActivity.onDestroy(CameraActivity.java:131)
at android.app.Activity.performDestroy(Activity.java:6407)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Please Register or Login to post a reply

1 Replies

N Nicolas Hinze

Using the old Camera API works correctly:

def take_a_picture
   settings = {:desired_width => 1280, :desired_height => 1280, :flash_mode => 'auto'}
  Camera::take_picture(url_for(:action => :camera_callback_new), settings)
end

  def camera_callback_new
    if @params['status'] == 'ok'
      WebView.execute_js("camera_callback_new('" + Rho::RhoApplication::get_blob_path(@params['image_uri']) + "','" + @params['image_uri'] + "');")
    elsif @params['status'] == 'error'
      alertSettings = Hash.new
      alertSettings['message'] = @params.to_s
      alertSettings['title'] = Localization::Fence_controller[:camera_error]
      alertSettings['buttons'] = [Localization::Fence_controller[:ok]]
      alertSettings['type'] = [Rho::Notification::TYPE_DIALOG]
      Rho::Notification.showPopup(alertSettings)
    end

CONTACT
Can’t find what you’re looking for?