尝试使用Zxing QR码阅读器API会导致强制关闭 [英] Trying to use Zxing QR code reader API results in force close
问题描述
我已经集成了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, callresolveActivity()
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 callstartActivity()
. 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屋!