0

我正在尝试通过意图生成 qrcode,但我总是得到ActivityNotFoundException. 我的库中有我的 core.jar。

这是我的代码:

intent = new Intent("com.google.zxing.client.android.ENCODE");
    intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
    intent.putExtra("ENCODE_DATA", "Hello World!");
    startActivity(intent);

这是日志:

10-12 20:47:09.457: E/AndroidRuntime(1347): FATAL EXCEPTION: main
10-12 20:47:09.457: E/AndroidRuntime(1347): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleqrcode/com.example.sampleqrcode.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.ENCODE cat=[android.intent.category.DEFAULT] (has extras) }
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.os.Looper.loop(Looper.java:137)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at java.lang.reflect.Method.invokeNative(Native Method)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at java.lang.reflect.Method.invoke(Method.java:511)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at dalvik.system.NativeStart.main(Native Method)
10-12 20:47:09.457: E/AndroidRuntime(1347): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.ENCODE cat=[android.intent.category.DEFAULT] (has extras) }
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.startActivityForResult(Activity.java:3190)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.startActivity(Activity.java:3297)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at com.example.sampleqrcode.MainActivity.onCreate(MainActivity.java:24)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Activity.performCreate(Activity.java:4465)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-12 20:47:09.457: E/AndroidRuntime(1347):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-12 20:47:09.457: E/AndroidRuntime(1347):     ... 11 more

我错过了什么吗?

4

2 回答 2

0

这意味着没有安装条形码扫描仪。您负责捕获ActivityNotFoundException和处理它,例如提示用户安装它。

更好的是,使用android-integration原始 zxing 项目中的代码。它是两个类,它在一个简单的 API 中包含了所有这样的细节。http://code.google.com/p/zxing/wiki/ScanningViaIntent

于 2012-10-12T07:28:24.783 回答
0
  1. 从这里在您的工作区中导入一个 zxing 库项目。

  2. 从库项目创建一个新项目。它将正常工作。

    您也可以访问此链接进行实施。

于 2012-10-12T06:01:28.497 回答