private void initCamera(SurfaceHolder surfaceHolder) {
   if (surfaceHolder == null) {
     throw new IllegalStateException("No SurfaceHolder provided");
   }
   if (cameraManager.isOpen()) {
     Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?");
     return;
   }
   try {
     cameraManager.openDriver(surfaceHolder);
     // Creating the handler starts the preview, which can also throw a RuntimeException.
     if (handler == null) {
       handler = new CaptureActivityHandler(this, decodeFormats, characterSet, cameraManager);
     }
     decodeOrStoreSavedBitmap(null, null);
   } catch (IOException ioe) {
     Log.w(TAG, ioe);
     displayFrameworkBugMessageAndExit();
   } catch (RuntimeException e) {
     // Barcode Scanner has seen crashes in the wild of this variety:
     // java.?lang.?RuntimeException: Fail to connect to camera service
     Log.w(TAG, "Unexpected error initializing camera", e);
     displayFrameworkBugMessageAndExit();
   }
 }
Esempio n. 2
0
 private void initCamera(SurfaceHolder surfaceHolder) {
   try {
     cameraManager.openDriver(surfaceHolder);
     // Creating the handler starts the preview, which can also throw a RuntimeException.
     if (handler == null) {
       handler = new CaptureActivityHandler(this, decodeFormats, characterSet, cameraManager);
     }
   } catch (IOException ioe) {
     Log.w(TAG, ioe);
     displayFrameworkBugMessageAndExit();
   } catch (RuntimeException e) {
     // Barcode Scanner has seen crashes in the wild of this variety:
     // java.?lang.?RuntimeException: Fail to connect to camera service
     Log.w(TAG, "Unexpected error initializing camera", e);
     displayFrameworkBugMessageAndExit();
   }
 }
 private void initCamera(SurfaceHolder surfaceHolder) {
   if (surfaceHolder == null) {
     throw new IllegalStateException("No SurfaceHolder provided");
   }
   if (cameraManager.isOpen()) {
     return;
   }
   try {
     // 打开Camera硬件设备
     cameraManager.openDriver(surfaceHolder);
     // 创建一个handler来打开预览,并抛出一个运行时异常
     if (handler == null) {
       handler =
           new CaptureActivityHandler(
               this, decodeFormats, decodeHints, characterSet, cameraManager);
     }
   } catch (IOException ioe) {
     Log.w(TAG, ioe);
     displayFrameworkBugMessageAndExit();
   } catch (RuntimeException e) {
     Log.w(TAG, "Unexpected error initializing camera", e);
     displayFrameworkBugMessageAndExit();
   }
 }