Parse barcodes if exists

This commit is contained in:
Sylvia van Os
2019-12-09 17:44:13 +01:00
parent 3d543dd23c
commit 2c7cb4769a

View File

@@ -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";