From 7eae23f65951d3aa4272528964cbbd000d103286 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Thu, 2 Nov 2017 11:54:25 +0000 Subject: [PATCH] Guard against a few rare errors from Play logs --- .../client/android/CaptureActivityHandler.java | 16 +++++++++------- .../client/android/result/ResultHandler.java | 4 ++-- .../zxing/client/result/VCardResultParser.java | 6 +++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/android/src/com/google/zxing/client/android/CaptureActivityHandler.java b/android/src/com/google/zxing/client/android/CaptureActivityHandler.java index c5bddd9e3..ad9982441 100755 --- a/android/src/com/google/zxing/client/android/CaptureActivityHandler.java +++ b/android/src/com/google/zxing/client/android/CaptureActivityHandler.java @@ -122,13 +122,15 @@ public final class CaptureActivityHandler extends Handler { } // Needed for default Android browser / Chrome only apparently - switch (browserPackageName) { - case "com.android.browser": - case "com.android.chrome": - intent.setPackage(browserPackageName); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Browser.EXTRA_APPLICATION_ID, browserPackageName); - break; + if (browserPackageName != null) { + switch (browserPackageName) { + case "com.android.browser": + case "com.android.chrome": + intent.setPackage(browserPackageName); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Browser.EXTRA_APPLICATION_ID, browserPackageName); + break; + } } try { diff --git a/android/src/com/google/zxing/client/android/result/ResultHandler.java b/android/src/com/google/zxing/client/android/result/ResultHandler.java index 7de8d84f9..d1f4a41e6 100644 --- a/android/src/com/google/zxing/client/android/result/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/result/ResultHandler.java @@ -201,7 +201,7 @@ public abstract class ResultHandler { // Only use the first name in the array, if present. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, ContactsContract.Contacts.CONTENT_URI); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); - putExtra(intent, ContactsContract.Intents.Insert.NAME, names != null ? names[0] : null); + putExtra(intent, ContactsContract.Intents.Insert.NAME, names != null && names.length > 0 ? names[0] : null); putExtra(intent, ContactsContract.Intents.Insert.PHONETIC_NAME, pronunciation); @@ -270,7 +270,7 @@ public abstract class ResultHandler { if (note != null) { aggregatedNotes.append('\n').append(note); } - if (geo != null) { + if (geo != null && geo.length >= 2) { aggregatedNotes.append('\n').append(geo[0]).append(',').append(geo[1]); } diff --git a/core/src/main/java/com/google/zxing/client/result/VCardResultParser.java b/core/src/main/java/com/google/zxing/client/result/VCardResultParser.java index 14545fa52..3e9d682b6 100644 --- a/core/src/main/java/com/google/zxing/client/result/VCardResultParser.java +++ b/core/src/main/java/com/google/zxing/client/result/VCardResultParser.java @@ -196,7 +196,11 @@ public final class VCardResultParser extends ResultParser { if ("uri".equals(valueType)) { // Don't actually support dereferencing URIs, but use scheme-specific part not URI // as value, to support tel: and mailto: - element = URI.create(element).getSchemeSpecificPart(); + try { + element = URI.create(element).getSchemeSpecificPart(); + } catch (IllegalArgumentException iae) { + // ignore + } } if (metadata == null) { List match = new ArrayList<>(1);