我想创建一个应用程序来生成使用 Zxing 作为库的条形码。我想要一个条形码图像。我在我的主要项目中使用了以下代码。
Intent intent = new Intent("com.google.zxing.client.android.Intents.Encode");
intent.setPackage("com.google.zxing.client.android");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra("ENCODE_FORMAT", "CODE_128");
intent.putExtra("ENCODE_DATA", "12345678912");
startActivity(intent);
但它给出了错误:
10-04 12:54:27.305: E/AndroidRuntime(399): FATAL EXCEPTION: main
10-04 12:54:27.305: E/AndroidRuntime(399): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.Intents.Encode pkg=com.google.zxing.client.android (has extras) }
10-04 12:54:27.305: E/AndroidRuntime(399): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.app.Activity.startActivityForResult(Activity.java:2817)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:672)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.Fragment.startActivity(Fragment.java:747)
10-04 12:54:27.305: E/AndroidRuntime(399): at com.check.MyFragment.onResume(MyFragment.java:62)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1371)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:418)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.os.Handler.handleCallback(Handler.java:587)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.os.Looper.loop(Looper.java:123)
10-04 12:54:27.305: E/AndroidRuntime(399): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-04 12:54:27.305: E/AndroidRuntime(399): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 12:54:27.305: E/AndroidRuntime(399): at java.lang.reflect.Method.invoke(Method.java:521)
10-04 12:54:27.305: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-04 12:54:27.305: E/AndroidRuntime(399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-04 12:54:27.305: E/AndroidRuntime(399): at dalvik.system.NativeStart.main(Native Method)
我也在清单中声明了活动。
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
如果我在这里遗漏了什么,请告诉我。