0

Part 1: As title suggest I am getting a java.lang.verifyError at a line in my code where I am checking if the device has a Flash.

if(packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
     //do something..
}

Part 2: Also, at another place in the code where I have

if(Build.VERSION.SDK_INT >= 23) {
 try {
    CameraManager camManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    // Usually front camera is at 0 position.
    if (camManager != null) {
        mcamid = camManager.getCameraIdList()[0];
        camManager.setTorchMode(mcamid, true);
    }
  } catch (CameraAccessException e) { }
}

then I get java.lang.VerifyError at this line: CameraManager camManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

Both errors only happen on Android 4.2 and 4.3 and no extra information is provided by Google Play ANR & Crashes.

Any insights on what I am doing wrong, and how it can be corrected?

Relevant Manifest Entries:

<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature
    android:name="android.hardware.camera.flash"
    android:required="false" />

<!-- android.permission-group.CAMERA -->
<uses-permission android:name="android.permission.CAMERA" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />

Update 1: On closer scrutiny I find that the java.lang.VerifyError is happening exactly on the line where I create a new Listener on Android 4.2 / 4.1

flashBtnListener = new FlashOnClickListener();

The class FlashOnClickListener() is an inner class in the same java file and does this in onClick() method:

if(Build.VERSION.SDK_INT >= 23) {
    try {
        CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        // Usually front camera is at 0 position.
        if (camManager != null) {
            mCameraId = camManager.getCameraIdList()[0];
            camManager.setTorchMode(mCameraId, true);
            theFlash.setImageResource(R.drawable.ic_highlight_black_24dp);
        }
    } catch (CameraAccessException e) {
    }
} else {
    try {
        mCamera = Camera.open();
        Camera.Parameters parameters = mCamera.getParameters();
        List<String> flashModes = parameters.getSupportedFlashModes();
        if (flashModes != null && flashModes.contains(android.hardware.Camera.Parameters.FLASH_MODE_TORCH)) {
            parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
            mCamera.setParameters(parameters);
            mCamera.startPreview();
            theFlash.setImageResource(R.drawable.ic_highlight_black_24dp);
        }
    } catch (Exception e) {

    }
}
Kevin
  • 1
  • 2
  • Share your `AndroidMenifest.xml` file. – Ghulam Moinul Quadir May 19 '18 at 04:42
  • confirm flash is available on your device then set. refer : https://stackoverflow.com/questions/13413938/how-to-check-if-device-has-flash-light-led-android – Rajasekaran M May 19 '18 at 06:07
  • @RajasekaranM That's exactly what I am trying to do - confirming the flash availability on the device by ` if(packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) ` but this throws java.lang.Error on Android 4.2 and 4.3 but works perfectly on other OS Versions. Do you mean to say that I need to write separate codes depending on OS Versions? Thanks! – Kevin May 21 '18 at 18:06
  • yes exactly, you need check the os version and check flash is available on phone. use this https://stackoverflow.com/questions/4918561/android-how-to-check-the-flash-light-is-available-on-device – Rajasekaran M May 22 '18 at 06:05

0 Answers0