Fail to connect to camera service
See original GitHub issueUsing Android SDK v.24
W/CameraBase: An error occurred while connecting to camera 0: Service not available W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView E/AndroidRuntime: FATAL EXCEPTION: cs-init Process: com.fuib.bridgest, PID: 19022 java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.<init>(Camera.java:556) at android.hardware.Camera.open(Camera.java:372) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:764) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:741)
Code:
public class LoginActivity extends AppCompatActivity {
private CodeScanner mCodeScanner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
CodeScannerView scannerView = findViewById(R.id.scanner_view);
mCodeScanner = new CodeScanner(this, scannerView);
mCodeScanner.setCamera(CodeScanner.CAMERA_BACK);
mCodeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), result.getText(), Toast.LENGTH_SHORT).show();
}
});
}
});
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCodeScanner.startPreview();
}
});
}
@Override
protected void onResume() {
super.onResume();
mCodeScanner.startPreview();
}
@Override
protected void onPause() {
mCodeScanner.releaseResources();
super.onPause();
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top GitHub Comments
You should request camera permission on API >= 23 https://github.com/yuriy-budiyev/lib-demo-app/blob/master/app/src/main/java/com/budiyev/android/libdemoapp/codescanner/CodeScannerActivity.java
E/AndroidRuntime: FATAL EXCEPTION: cs-init Process: com.lightlogistics.vaast, PID: 5369 java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.<init>(Camera.java:637) at android.hardware.Camera.open(Camera.java:458) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812) E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash’s UncaughtExceptionHandler java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.<init>(Camera.java:637) at android.hardware.Camera.open(Camera.java:458) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.initialize(CodeScanner.java:835) at com.budiyev.android.codescanner.CodeScanner$InitializationThread.run(CodeScanner.java:812)
i have asked permission and it works but some times app crashes i am using ‘com.budiyev.android:code-scanner:2.1.0’ version