尝试使用Zxing QR码阅读器API会导致强制关闭 [英] Trying to use Zxing QR code reader API results in force close

查看:73
本文介绍了尝试使用Zxing QR码阅读器API会导致强制关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经集成了Zxing API并使用以下代码:

I have integrated the Zxing API and use this code:

Intent data = new Intent("com.google.zxing.client.android.SCAN");

并通过以下代码获取结果:

And getting the result with this code:

String contents = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");

但是当我运行这段代码时,应用程序将要求强制关闭.

But when I run this code, the app will ask to force close.

推荐答案

将意图发送给startActivity(),您必须始终检查用户是否具有可以处理该意图的任何应用:

When sending an Intent to startActivity(), you must always check if the user has any apps that can handle the intent:

警告:用户可能没有任何应用程序可以处理您发送给

Caution: It's possible that a user won't have any apps that handle the implicit intent you send to startActivity(). If that happens, the call will fail and your app will crash. To verify that an activity will receive the intent, call resolveActivity() on your Intent object. If the result is non-null, then there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that issues the intent.

这篇关于尝试使用Zxing QR码阅读器API会导致强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆