From 2c7cb4769ad97d1ffdfa0b499f29cec5b45f63c1 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Mon, 9 Dec 2019 17:44:13 +0100 Subject: [PATCH] Parse barcodes if exists --- .../protect/card_locker/PkpassImporter.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/PkpassImporter.java b/app/src/main/java/protect/card_locker/PkpassImporter.java index df4fc96b4..d8d573a4e 100644 --- a/app/src/main/java/protect/card_locker/PkpassImporter.java +++ b/app/src/main/java/protect/card_locker/PkpassImporter.java @@ -3,6 +3,7 @@ package protect.card_locker; import android.content.Context; import android.net.Uri; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -46,8 +47,34 @@ public class PkpassImporter { String store = json.getString("organizationName"); String note = json.getString("description"); - String cardId = json.getJSONObject("barcode").getString("message"); - String barcodeType = json.getJSONObject("barcode").getString("format").substring("PKBarcodeFormat".length()); + + // https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html#//apple_ref/doc/uid/TP40012026-CH2-SW1 + // barcodes is the new field + // barcode is deprecated, but used on old iOS versions, so we do fall back to it + JSONObject barcode = null; + JSONArray barcodes = null; + + try + { + barcodes = json.getJSONArray("barcodes"); + } catch (JSONException ex) { } + + if(barcodes != null) + { + barcode = barcodes.getJSONObject(0); + } + else + { + barcode = json.getJSONObject("barcode"); + } + + if(barcode == null) + { + return null; + } + + String cardId = barcode.getString("message"); + String barcodeType = barcode.getString("format").substring("PKBarcodeFormat".length()); if(barcodeType.equals("QR")) { barcodeType = "QR_CODE";