在Zxing吧code应用程序获取相机错误 [英] Getting Camera error in Zxing Barcode Application
问题描述
我想使用Zxing图书馆发展吧code扫描仪。
I am trying to use Zxing Library for developing a barcode scanner.
我的活动如下:
public class Scanner extends Activity {
private static final String PACKAGE = "com.test.scan";
private static final String SCANNER = "com.google.zxing.client.android.SCAN";
private static final String SCAN_FORMATS = "UPC_A,UPC_E,EAN_8,EAN_13,CODE_39,CODE_93,CODE_128";
private static final String SCAN_MODE = "QR_CODE_MODE";
public static final int REQUEST_CODE = 1;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button ok;
ok = (Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent scanIntent = new Intent(SCANNER);
scanIntent.setPackage(PACKAGE);
scanIntent.addCategory(Intent.CATEGORY_DEFAULT);
scanIntent.putExtra("SCAN_FORMATS", SCAN_FORMATS);
scanIntent.putExtra("SCAN_MODE", SCAN_MODE);
try {
startActivityForResult(scanIntent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// TODO: Exception handling
}
}
});
}
另外清单文件:
Also manifest file:
<activity android:name=".Scanner"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.PreferencesActivity"
android:label="@string/preferences_name">
</activity>
<activity android:name="com.google.zxing.client.android.HelpActivity"
android:screenOrientation="user">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.share.ShareActivity"
android:label="@string/share_name" android:screenOrientation="user"
android:theme="@android:style/Theme.Light">
<intent-filter>
<action android:name="com.google.zxing.client.android.SHARE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.CAMERA"
不过,我收到以下错误:
But I am getting the following error:
抱歉,Android相机遇到问题,你可能需要重新启动设备。
"Sorry, the Android camera encountered a problem. You may need to restart the device".
我跟一些博客。
日志:
Unexpected error initializating camera
01-27 10:40:48.281: WARN/CaptureActivity(1007): java.lang.RuntimeException: Fail to connect to camera service
01-27 10:40:48.281: WARN/CaptureActivity(1007): at android.hardware.Camera.native_setup(Native Method)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at android.hardware.Camera.<init>(Camera.java:185)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at android.hardware.Camera.open(Camera.java:165)
十月1号至27日:40:48.281:WARN / CaptureActivity(1007):在com.google.zxing.client.android.camera.CameraManager.openDriver(CameraManager.java:126)
10月1日至27号:40:48.281:WARN / CaptureActivity(1007):在com.google.zxing.client.android.CaptureActivity.initCamera(CaptureActivity.java:606)
10月1日至27号:40:48.281:WARN / CaptureActivity(1007):在com.google.zxing.client.android.CaptureActivity.surfaceCreated(CaptureActivity.java:346)
10月1日至27号:40:48.281:WARN / CaptureActivity(1007):在android.view.SurfaceView.updateWindow(SurfaceView.java:532)
10月1日至27号:40:48.281:WARN / CaptureActivity(1007):在android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at com.google.zxing.client.android.camera.CameraManager.openDriver(CameraManager.java:126)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at com.google.zxing.client.android.CaptureActivity.initCamera(CaptureActivity.java:606)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at com.google.zxing.client.android.CaptureActivity.surfaceCreated(CaptureActivity.java:346)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
01-27 10:40:48.281: WARN/CaptureActivity(1007): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
感谢
Sneha
Thanks
Sneha
推荐答案
这意味着返回的设备空 <$ C C $>从 Camera.open()
,它不应该永远做。它视为设备缺陷。我不知道你将如何调试它为什么是这样做的,但是这就是原因。
This means the device returned null
from Camera.open()
and it shouldn't ever do that. It's treated as a device bug. I am not sure how you would debug why it is doing this, but that's the cause.
我已经看到了这一点始终唯一的一次是有一个前置摄像头,只有Android 2.2的设备。访问一个前置摄像头只出现在了Android 2.3的API和previous Camera.open()
API方法只能返回一个后置摄像头。因此,这些返回空
。它是一个设备的错误,真的,因为他们确实需要运行的是Android 2.3,让应用程序使用了前置摄像头。
The only time I have seen this happen consistently is on Android 2.2 devices that have a front camera, only. The API for accessing a front camera only appeared in Android 2.3, and the previous Camera.open()
API method may only return a rear-facing camera. So these return null
. And it is a device bug, really, since they really need to be running Android 2.3 to let apps use a front camera.
这篇关于在Zxing吧code应用程序获取相机错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!