我使用了Android ADT套件,开发工作。 在线阅读多导后,我已经添加了包com.dm.zbar.android.scanner到我的项目。 我已经包括了文件CameraPreview.java,ZBarConstants.java和ZBarScannerActivity.java在包中。 尽管这一切的ZBAR_SCANNER_REQUEST变种的类ScanActivity.java(由我创造的,而是用zbar和方法)不能被解析为一个变量。 除了这个变量的一切被接受。 任何想法,这是为什么发生? 注:我的库文件夹包含在这里的一切:
https://github.com/DushyanthMaguluru/ZBarScanner/tree/master/ZBarScannerLibrary/libs
和zbar.jar包含在构建路径上。
ScanActivity:
package com.xx.xxx;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import net.sourceforge.zbar.Symbol;
public class ScanActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
}
public void launchScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public void launchQRScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ZBAR_SCANNER_REQUEST:
case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
}
break;
}
}
}
万一它是相关的:AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xx.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:icon="@drawable/ic_launcher"
android:label="xx"
android:theme="@style/AppTheme" >
<activity android:name="com.xx.xxx.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.xx.xxx.WvActivity" />
<activity android:name="com.xx.xxx.ScanActivity" />
<activity
android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"
android:screenOrientation="landscape" />
</application>