1

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.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
amir
  • 31
  • 6

2 Answers2

1

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.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
0

Go through this. App is crashing because Zxing app is not installed in the mobile. I gave a detailed answer in the same link.

Community
  • 1
  • 1
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109