code-scanner
code-scanner copied to clipboard
Failed to connect to Camera Service
Hi, I am using library version 2.1.0 and on Xiaomi device(Os 5.1.1) I am always getting below exception:
Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.
[edited] I restarted the device and the app now works as intended. I reproduced the crash with a fresh install on a phone that never had this app, so my app couldn't have been the one not releasing the camera resource. I suspect it's the MIUI camera app that "forgets" to release the camera sometimes, as I only get crashes on Xiaomi devices with MIUI (Android One devices are not affected, I tested it)
[Original comment] Hi, I am also using library version 2.1.0 and have the same crash with a Xiaomi Redmi K20 (Android 10):
Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.
Hi, I am also using library version 2.1.0 and the same crash with Xiaomi Android version 10
Hi, I am using library version 2.1.0 and on Xiaomi device(Os 5.1.1) I am always getting below exception:
Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera. + 533(Camera.java:533) at android.hardware.Camera.open + 365(Camera.java:365) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize + 835(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run + 812(CodeScanner.java:812)
Because Android 10 not supported.
I have the same issue
Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.<init>(Camera.java:667) at android.hardware.Camera.open(Camera.java:503) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812)
Facing the same issue, the problem occurs when I try to initialize the camera the second time in a row,
W: An error occurred while connecting to camera: 0
W: java.lang.RuntimeException: Fail to connect to camera service
W: at android.hardware.Camera.
I have the same issue
Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.<init>(Camera.java:667) at android.hardware.Camera.open(Camera.java:503) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812)
Did you found any solution yet?
I haven't found solution yet.
On Thu, Dec 31, 2020 at 1:28 PM YasinEnu [email protected] wrote:
I have the same issue Fatal Exception: java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.
(Camera.java:667) at android.hardware.Camera.open(Camera.java:503) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812) Did you found any solution yet?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yuriy-budiyev/code-scanner/issues/80#issuecomment-752849450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA73IDB35TMTLRI634CAD7LSXQDWZANCNFSM4JWUFUFA .
same here
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:747)
at android.hardware.Camera.open(Camera.java:549)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835)
at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812)
the problem is with the mobile no giving camera permission to your app. if you went to setting -> app -> {your app} -> permissions and enabled camera permission it works fine. so i guess you got to ask for permission of camera first.
helpful links:
- https://developer.android.com/training/permissions/requesting
- https://www.techotopia.com/index.php/Kotlin_-_Making_Runtime_Permission_Requests_in_Android
The library provides a mechanism for intercepting camera initialization errors. To do this, when initializing the CodeScaner, you must set the ErrorCallback using setErrorCallback (final ErrorCallback errorCallback). If an error (any) occurs during initialization, the library checks for the presence of this callback and, if not, throws an error, and if there is, processes it.
try {
initialize();
} catch (final Exception e) {
releaseResourcesInternal();
final ErrorCallback errorCallback = mErrorCallback;
if (errorCallback != null) {
errorCallback.onError(e);
} else {
throw e;
}
}
Check camera permissions and update to 2.1.2 for better error handling.