Reputation: 9895
In my PhotoCaptureActivity.java's onCreate() I have:
OrientationEventListener oeL = new OrientationEventListener(this) {
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
try {
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(currentCameraId, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
if(camera != null) {
Camera.Parameters parameters = camera.getParameters();
parameters.setRotation(rotation);
savingRotation = rotation;
}
} catch(Exception e) {
return;
}
}
};
oeL.enable();
Exception occurred on this line: android.hardware.Camera.getCameraInfo(currentCameraId, info);
java.lang.RuntimeException: Fail to get camera info
at android.hardware.Camera.getCameraInfo(Camera.java)
at cic.signin.macio.jun.activities.PhotoCaptureActivity$3.onOrientationChanged(PhotoCaptureActivity.java:70)
at android.view.OrientationEventListener$SensorEventListenerImpl.onSensorChanged(OrientationEventListener.java:143)
at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:584)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(NativeStart.java)
My question is: if android.hardware.Camera.getCameraInf(currentCameraId, info) in OrientationEventListener's onOrientationChanged() was called too frequently caused the exception? How to solve the issue? btw, this exception didn't occur on 4.0 and 4.1, only occurred on certain device.
Upvotes: 16
Views: 5128
Reputation: 4651
Wild guess here - its not related to your code, reset the device and try again. Sometimes my Camera (or even the flash stops working) and the only to fix it is to reset the device.
Upvotes: 3