I wanted to make use of the zxing library to detect qrcodes in my app.
But for the apps viewing purpose, i had to change the custom display
orientation to portrait. Hence i had to integrate the whole zxing
library into my app and addded camera.setDisplayOrientation(90) to the
openDriver() method. After doing this, the program works, but I get
"Runtime exceptions : Fail to connect to camera service" randomly.

public void openDriver(SurfaceHolder holder) throws IOException {
  if (camera == null) {
      camera = Camera.open();
      camera.setDisplayOrientation(90);

      if (camera == null) {
          throw new IOException();
      }
  }
  camera.setPreviewDisplay(holder);
  if (!initialized) {
  initialized = true;
  configManager.initFromCameraParameters(camera);
}
configManager.setDesiredCameraParameters(camera);

SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(context);
reverseImage = prefs.getBoolean(PreferencesActivity.KEY_REVERSE_IMAGE,
false);
if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) {
  FlashlightManager.enableFlashlight();
 }
}

public void closeDriver() {
    if (camera != null) {
        FlashlightManager.disableFlashlight();
        camera.release();
        camera = null;
        framingRect = null;
        framingRectInPreview = null;
    }
}

/**
 * Asks the camera hardware to begin drawing preview frames to the
screen.
 */
public void startPreview() {
    if (camera != null && !previewing) {
        camera.startPreview();
        previewing = true;
    }
}

/**
 * Tells the camera to stop drawing preview frames.
 */
public void stopPreview() {
    if (camera != null && previewing) {
        if (!useOneShotPreviewCallback) {
            camera.setPreviewCallback(null);
        }
        camera.stopPreview();
        previewCallback.setHandler(null, 0);
        autoFocusCallback.setHandler(null, 0);
        previewing = false;
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to