当应用程序的主视图在屏幕上时,我需要在我的Android应用程序中连续扫描QR码.主视图应包含带摄像头预览的窗口,但不包含全屏摄像头预览.
用法示例:包含扫描的QR码列表和相机预览的主视图.扫描新的QR码时,会将其添加到列表中.
可能吗?
我按照本教程学习如何构建可以扫描QR码的Android应用程序.
这是完整的代码.我使用等级添加了Google Play服务compile 'com.google.android.gms:play-services:7.8.0'.
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bitinvent.io.qrscanner" >
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<SurfaceView
android:id="@+id/cameraView"
android:layout_width="640px"
android:layout_height="480px"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/infoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cameraView"
android:layout_marginLeft="16dp"
android:text="Nothing to read"
android:textSize="20sp"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
package bitinvent.io.qrscanner;
import …Run Code Online (Sandbox Code Playgroud)