我正在尝试在我的Android应用中实现QR码阅读器。我已按照以下步骤操作:
从zxing.zip,/ android和/ core创建了一个示例库项目
将创建的库添加到我的应用
我的代码如下:
public class main extends Activity {
/** Called when the activity is first created. */
Button scanButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scanButton = (Button) findViewById(R.id.button1);
scanButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
扫描仪无法启动,我收到此错误:
05-08 14:12:03.313: ERROR/AndroidRuntime(718): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.scanner.demo-2.apk]
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanner.demo" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".main" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:2)
为什么要把它放在你的清单中?
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
...
</activity>
您是在调用内部活动还是来自Zxing的应用程序?
答案 1 :(得分:2)
这很困惑。你似乎想要按Intent
进行整合,这就是上半部分所做的事情。但是你似乎已经复制了我们的Manifest。为什么?请删除它。它不是必需的,会导致您的错误,如果您将其留下,则会干扰我们的应用。
这就是您所需要的:https://code.google.com/p/zxing/wiki/ScanningViaIntent