我是Android的开发人员,但我需要知道如何在Activity Layout中使用相机 .
我知道我需要使用Surface View在活动中插入摄像头,目前我的应用程序正在使用默认摄像头使用Google Vision阅读QR码(按钮打开摄像头,用户拍摄照片,我的应用感知活动结果) .
但我真的需要在应用程序中使用实时扫描程序实现该功能 .
有人可以指导我吗?
使用库,不要将相机放在Activity上,只需调用相机即可 . 你可以查看这个链接并尝试实现它:https://github.com/zxing/zxing
Here is how I implemented something similar to what you need.
compile 'com.journeyapps:zxing-android-embedded:3.5.0'
https://github.com/journeyapps/zxing-android-embedded
-Below是我制作布局文件的方式:
<!-- language: lang-xml --> <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.journeyapps.barcodescanner.DecoratedBarcodeView android:id="@+id/view_scanner" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/view_footer" android:soundEffectsEnabled="true" /> <LinearLayout android:id="@+id/view_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:orientation="horizontal"> <LinearLayout android:id="@+id/view_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center|top" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/_10sdp" android:layout_marginTop="@dimen/_10sdp" android:src="@drawable/ic_back_light" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/_50sdp" android:gravity="right|top"> <ImageView android:id="@+id/iv_flash" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/_10sdp" android:layout_marginTop="@dimen/_10sdp" android:src="@drawable/ic_flash_inactive" /> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/view_footer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:gravity="center" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginLeft="@dimen/_10sdp" android:layout_marginRight="@dimen/_10sdp" android:background="@android:color/darker_gray" /> <TextView android:id="@+id/code_info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="@string/font_sans_serif_light" android:padding="@dimen/_15sdp" android:text="@string/app_name" android:textColor="@android:color/white" android:textSize="@dimen/_15sdp" /> </LinearLayout> </FrameLayout>
所以现在,DecorativeBarcodeView作为您布局中的主要扫描区域 .
private DecoratedBarcodeView barcodeView; barcodeView = (DecoratedBarcodeView) findViewById(R.id.view_scanner); barcodeView.setStatusText(""); barcodeView.decodeContinuous(callback);
private BarcodeCallback callback = new BarcodeCallback() { @Override public void barcodeResult(BarcodeResult result) { //Process your scan result here String resultString = result.getText(); } @Override public void possibleResultPoints(List<ResultPoint> resultPoints) { } };
希望这可以帮助 .
2 回答
使用库,不要将相机放在Activity上,只需调用相机即可 . 你可以查看这个链接并尝试实现它:https://github.com/zxing/zxing
Here is how I implemented something similar to what you need.
https://github.com/journeyapps/zxing-android-embedded
-Below是我制作布局文件的方式:
所以现在,DecorativeBarcodeView作为您布局中的主要扫描区域 .
希望这可以帮助 .