可能重复:
Integration ZXing library directly into my Android application
我遇到了在我的应用程序中集成Zxing库的问题。问题是我想创建一个独立的条形码扫描器应用程序,并尝试了所有可能的方法将它集成到我的项目,如一些论坛和堆栈溢出主题中提到但仍然无法这样做。有人可以在这方面帮助我,以便我可以继续前进。这是我在尝试here:
时提到的步骤时遇到的例外情况01-29 16:00:38.703: E/AndroidRuntime(30568): FATAL EXCEPTION: main
01-29 16:00:38.703: E/AndroidRuntime(30568): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.app.Activity.startActivityForResult(Activity.java:2827)
01-29 16:00:38.703: E/AndroidRuntime(30568): at com.scanner.sample.MainActivity$1.onClick(MainActivity.java:31)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.view.View.performClick(View.java:2485)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.view.View$PerformClick.run(View.java:9080)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.os.Handler.handleCallback(Handler.java:587)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.os.Looper.loop(Looper.java:130)
01-29 16:00:38.703: E/AndroidRuntime(30568): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-29 16:00:38.703: E/AndroidRuntime(30568): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 16:00:38.703: E/AndroidRuntime(30568): at java.lang.reflect.Method.invoke(Method.java:507)
01-29 16:00:38.703: E/AndroidRuntime(30568): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-29 16:00:38.703: E/AndroidRuntime(30568): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-29 16:00:38.703: E/AndroidRuntime(30568): at dalvik.system.NativeStart.main(Native Method)
这是我的MainActivity:
公共类MainActivity扩展了Activity {
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.textView1);
Button mQrcode = (Button)findViewById(R.id.button1);
mQrcode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
// "PRODUCT_MODE
// for
// bar codes
startActivityForResult(intent, 0);
} catch (Exception e) {
Uri marketUri = Uri
.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");
text.setText(contents);
Log.v("**************Result : *****************", contents);
Log.v("**************Result formatted : *****************", format);
}
}
}
}
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanner.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
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>
</manifest>