mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-18 05:36:39 -04:00
Parse barcodes if exists
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user