Android SDK - Developer Utilities

DOCS

Last updated: Aug 15th, 6:12am

Describes the classes exposed in the Android mobile payments SDK that facilitate the developer’s use of the SDK to build, configure, and monitor a working reference app, but do not represent functional modules of the app behavior.

Bluetooth LE Library Utility

The com.paydiant.android.bluetooth.ble utility class implements a set of Bluetooth Low Energy (BLE) library classes that a developer can to configure the app to interact directly with a device, such as a POS, that is broadcasting the BLE service.

Ultimately, this implementation enables the mobile payments app to pair with the BLE service and read emitted beacons to initiate interaction with the WLW SDK, such as obtaining a checkout token value or activating an offer.

To use the BLE library utility classes, set up your development environment so your project meets the following minimum requirements:

  1. Reference Android 4.3 (API level 18) or higher in your project.
  2. Update your AndroidManifest.xml file to set the target SDK version to 18 or higher: android:targetSdkVersion="18".
  3. Make sure your project references the BLELibrary.apklib included in this Android SDK package (libs/BLE-Library). Refer to the README file located in the same directory for additional instructions.

The methods of the Bluetooth utility allow the developer to initialize the Bluetooth libraries and scan for supported BLE signals.

The following methods all throw BLEServiceProviderException; with event-specific error information.

Initialize the BLE service

ItemDescription
Methodpublic void init (Context context);
Creates an instance of the Bluetooth service class using the provided parameters.

context - runtime android context in which the BLE service is started

Check status

ItemDescription
Methodpublic getBLEStatus();
Checks the current initialization state of the BLE service on the current device.
ReturnsOne of the following values that indicates the status of the service:

BLE_NOT_SUPPORTED_ERROR
BLE_STATE_TURNED_OFF
BLE_STATE_TURNED_ON

Start scanning

ItemDescription
Methodpublic int startScan(UUID[] serviceUuids);
Kicks off a scan for BLE devices within the geo-perimeter that match the specified UUIDs representing supported devices relevant to the mobile payments app.

or public int startScan(UUID[] serviceUuids, long timeout);
An overloaded instance of the method that allows the developer to specify a duration for scanning, after which, if a UUID match has not been detected, the service will stop scanning.
ParametersserviceUuids - a list of BLE device UUIDs that are relevant to the app.

Check scanning

ItemDescription
Methodpublic isScanning();
Checks the current state of the BLE service to determine whether it is actively scanning for BLE devices in the vicinity.
ReturnsTRUE - the service is actively scanning
FALSE - the serice is not actively scanning

Stop scanning

ItemDescription
Methodpublic stopScanning();
Instructs the service to stop scanning for BLE devices.

Release BLE resources

ItemDescription
Methodpublic release();
Releases all the resources currently consumed by the BLEServiceProvider class and performs cleanup operations to enable the service to scan for a new BLE device.

Set BLE listener

ItemDescription
Methodpublic void setBLEServiceProviderListener (IBLEServiceProviderListener listener);
Sets an implementation of the BLEServiceProvider listener interface for the purpose of invoking relevant callback methods to be returned by the Bluetooth library.

listener - an instance of the com.paydiant.android.bluetooth.ble.IBLEServiceProviderListener class.

Bluetooth Callbacks

The callback methods of the Bluetooth Library utility enable the developer to configure relevant behavior in the app to be invoked based on the results of the app’s interaction with a supported BLE device.

Device discovered

ItemDescription
Methodpublic void onDeviceDiscovery(BLEDevice device, BLEScanRecord rawData, init rssi);
Invoked when a matched remote BLE device is detected during scanning.

device - an instance of the device data object that identifies the matched BLE device.
rawData - the characteristic value representation read from the LE emission. Since different LE devices may represent this data differently, developers should decode the raw data returned according to LE manufacturer specifications.
rawData is returned instead.
rssi - The RSSI value published by the Bluetooth device hardware that represents the power and distance of the detected BLE device relevant to the mobile payments device. This value will be 0 if no RSSI data is returned.

Ad device discovered

ItemDescription
Methodpublic void onDeviceDiscoveredWithAdData(BLEDevice device, BLEScanRecord rawData, init rssi);
Invoked only when a discovered BLE device contains advertisement data.

device - an instance of the device data object that identifies the matched BLE device.
rawData - The advertising data value. Since different LE devices may represent this data differently, developers should decode the raw data returned according to LE manufacturer specifications.
rssi - The RSSI value published by the Bluetooth device hardware that represents the power and distance of the detected BLE device relevant to the mobile payments device. This value will be 0 if no RSSI data is returned.

WLW token device discovered

ItemDescription
Methodpublic void onDeviceDiscoveredWithPydtToken(BLEDevice device, BLEScanRecord rawData, init rssi);
Invoked only when a discovered BLE device contains a WLW checkout token for initiating a transaction.

device - an instance of the device data object that identifies the matched BLE device.
rawData - the checkout token data value. Since different LE devices may represent this data differently, developers should decode the raw data returned according to LE manufacturer specifications.
rssi - the RSSI value published by the Bluetooth device hardware that represents the power and distance of the detected BLE device relevant to the mobile payments device. This value will be 0 if no RSSI data is returned.

Device connected

ItemDescription
Methodpublic onDeviceConnect(BLEDevice device);
Invoked when the Android device successfully connects (pairs) with the detected BLE device.

device - An instance of the device data object that identifies the matched BLE device.

Device status updated

ItemDescription
Methodpublic onDeviceStateChanged(int state);
Invoked when the status of a matched BLE device changes.

state - An integer value representing the BLE device status to which the state has been changed. The value for this parameter will be one of the following:

10 - BLE_STATE_TURNED_OFF
11 - BLE_STATE_TURNING_ON
12 - BLE_STATE_TURNED_ON
13 - BLE_STATE_TURNING_OFF

Service discovered

ItemDescription
Methodpublic onServiceDiscovery(BLEDevice device, List<BLEService> services);
Invoked when the BLE device advertises a service that the Android device has registered as relevant.

device - an instance of the device data object that identifies the matched BLE device.
services - an array of BLEService objects representing one or more registered services that have been discovered.

Characteristic read

ItemDescription
Methodpublic onCharacteristicRead(BLEDevice device, BLEService service, BLECharacteristic characteristic);
Invoked when the Android device successfully reads a specific data value from a matched BLE service.

device - an instance of the device data object that identifies the matched BLE device.
service - the BLEService object identifying the service from which the characteristic was read.
characteristic - the BLECharacteristic object identifying the specific data value that was read. Characteristic values are returned as rawData and will need to be decoded per LE device manufacturer specifications.

All characteristics read

ItemDescription
Methodpublic onAllCharacteristicsRead(BLEDevice device, BLEService service, List<BLECharacteristic> characteristics);
Invoked when the BLE device successfully reads the entire set of data values advertised by a matched BLE service.

device - an instance of the device data object that identifies the matched BLE device.
service - The BLEService object identifying the service from which the characteristics were read.
characteristics - An array of BLECharacteristic objects representing one or more data values that were successfully read from the BLE device. Characteristic values are returned as rawData and will need to be decoded per LE device manufacturer specifications.

Scanning stopped

ItemDescription
Methodpublic onScanStop();
Invoked when the BLE device stops scanning for matched BLE devices.

BLE error occurred

ItemDescription
Methodpublic onError(BLEException e);
Invoked when the Android device encounters an error interacting with the BLE utility.

Heartbeat Utility

The com.paydiant.android.net.Reachability utility class allows a developer to routinely check the connectivity between the app and the mobile gateway. When enabled, the heartbeat events can be listened for through the Android broadcast receivers by registering for the Reachability.REACHABILITY_ACTION intent action. Then, connectivity status can be obtained from the intent's

    1Reachability.EXTRA_R
    2EACHABILITY_SUCCESS
    Boolean extra value. Successful connectivity checks return TRUE and failed connectivity checks return FALSE.

    The methods of the heartbeat utility enable the developer to create an instance of the reachability class, as well as enable and disable the status checks.

    Constructor

    ItemDescription
    Methodpublic Reachability(Context context, int reachabilityInterval, int retryAttempts, int retryAttemptInterval)
    Creates an instance of the Reachability class using the provided parameters.

    Start checking

    ItemDescription
    Methodpublic synchronized void start()
    or
    public void startReachableCheck()
    Starts the heartbeat. The WLW (Paydiant)’s Logging Utility must be initialized prior to starting the heartbeat.

    Stop checking

    ItemDescription
    Methodpublic void stopRechableCheck()
    Stops the heartbeat.

    Device Property Utility

    The com.paydiant.android.core.util.DevicePropertyUtil utility class exposes the methods that obtain information about the device on which the app is running for operational and troubleshooting purposes.

    These methods enable a developer to retrieve and use device data such as the hardware, OS, and network information.

    Retrieve device properties

    ItemDescription
    Methodpublic static Map < String, String > retrieveDeviceProperties(ContextWrapper deviceContext)
    Gets the device id, manufacturer, brand, model, CPU architecture, network operator (if available) and the OS release version information.
    KeysUse the following keys defined in com.paydiant.android.core.util.IDevicePropertyCodes to extract the values from the returned Map.

    Device - IDevicePropertyCodes#DEVICE_ID
    Manufacturer - IDevicePropertyCodes#MANUFACTURER
    Brand - IDevicePropertyCodes#BRAND
    Model - IDevicePropertyCodes#MODEL
    CPU Architecture - IDevicePropertyCodes#CPU_ARCHITECT
    Network Operator - IDevicePropertyCodes#NETWORK_OPERATOR_NAME
    OS Build Version - IDevicePropertyCodes#BUILD_VERSION

    Retrieve system process and memory information

    ItemDescription
    Methodpublic static Map < String, String > retrieveCurrentSystemInfo(ContextWrapper deviceContext)
    Gets the available memory and the active processes count information.
    KeysUse the following keys defined in com.paydiant.android.core.util.IDevicePropertyCodes to extract the values from the returned Map.

    Active Processes -IDevicePropertyCodes#NO_OF_RUNNING_PROCESSES
    Available Memory - IDevicePropertyCodes#AVAILABLE_MEMORY

    Retrieve active network information

    ItemDescription
    Methodpublic static Map < String, String > retrieveActiveNetworkInfo(ContextWrapper deviceContext)
    Gets information about the current active network.
    KeysUse the following keys defined in com.paydiant.android.core.util.IDevicePropertyCodes to extract the values from the returned Map.

    Active Network Type - IDevicePropertyCodes#ACTIVE_NETWORK_TYPE.

    Valid values are:
    Wi-Fi - IDevicePropertyCodes#ACTIVE_NETWORK_TYPE_WIFI
    Cellular - IDevicePropertyCodes#ACTIVE_NETWORK_TYPE_MOBILE
    SSID (Wi-Fi Only) - IDevicePropertyCodes#WIFI_SSID
    Mac Address (Wi-Fi Only) -IDevicePropertyCodes#WIFI_MAC_ADDRESS
    Network Operator (Cellular Only) - IDevicePropertyCodes#NETWORK_OPERATOR_NAME

    App Utility

    The com.paydiant.android.common.util.AppUtils utility class provides functionality to retrieve app related information for troubleshooting and support purposes. These methods enable a developer to retrieve and use app data such as the version and the current state.

    Retrieve app label

    ItemDescription
    Methodpublic static String getApplicationLabel(Context context)
    Gets the value of the android:label as defined in the AndroidManifest.xml file.

    context - current android content

    App is in background

    ItemDescription
    Methodpublic static boolean isAppInBackground(Context context)
    Indicates if the app is in background or not.

    App Authenticity Verification Utility

    The com.paydiant.android.common.util.AppVerificationUtils utility class provides functionality to validate the app's authenticity for the purpose of heightened security.

    This utility exposes a single method to verify the fingerprint of an app's original signed certificate against that of the current running app. To use this method, find the JAR file and usage.txt file in the tools folder of the Android SDK bundle. The JAR file should be used to generate the fingerprint value. The usage.txt file provides instructions on how to use this JAR file.

    Verify app signature

    ItemDescription
    Methodpublic static void verifyAppSignature(Context context, long[] keyFingerprint, IVerificationCallback verificationCallback)

    context - Specifies the current Android context.
    keyFingerprint - The fingerprint value generated using the JAR file in the Android SDK bundle provided by the WLW.
    verificationCallback - instance of an implementation of the AppVerificationUtils.IVerificationCallback interface, which gets called when the app verification completes.

    Date Time Conversion Utility

    The com.paydiant.android.common.util.DateUtils utility class provides functionality to convert the timestamp associated with a mobile app event to the local time of the device.

    Convert time to device timezone

    ItemDescription
    MethodDate convertDateToLocal(String datetimePattern, String datatimeValue)
    Gets the date and date format associated with an event in the app, then converts the timestamp from UTC time-zone to the local time-zone of the device and returns the converted value in the original format.

    datetimePattern - Specifies the format used by the datetime value to be converted.
    datatimeValue - The datetime value to convert.

    Cryptographic Utility

    The com.paydiant.android.common.util.CryptoUtil utility class provides the functionality to encrypt or decrypt sensitive data for security purposes. These methods exposed by the cryptographic utility enable the developer to quickly and securely encode data in a variety of ways to protect it from malicious interception.

    Encrypt as string

    ItemDescription
    Methodpublic static String encrypt(String seed, String cleartext)
    Encrypts the provided cleartext value with the use of the "AES" algorithm and the provided seed parameter.

    Decrypt as string

    ItemDescription
    Methodpublic static String decrypt(String seed, String encrypted)
    Decrypts the encrypted value with the use of the "AES" algorithm and the provided seed parameter.

    Encode string to hex format

    ItemDescription
    Methodpublic static String toHex(String txt)
    Converts the provided string to the equivalent hex representation.

    Decode hex string to string

    ItemDescription
    Methodpublic static String fromHex(String hex)
    Decodes the provided hex string to the original string.

    Decode hex string to byte[]

    ItemDescription
    Methodpublic static byte[] toByte(String hexString)
    Decodes the provided hex string to a byte array.

    Encode byte[]

    ItemDescription
    Methodpublic static String toHex(byte[] buf)
    Converts the provided byte array to the equivalent hex representation.

    Generate MD5 digest

    ItemDescription
    Methodpublic static byte[] md5Digest(byte[] data)
    Generates MD5 digest for the provided data.

    Generate SHA-256 digest

    ItemDescription
    Methodpublic static byte[] sha256Digest(byte[] data)
    Generates SHA-256 digest for the provided data.

    WLW Wi-Fi Configuration Parser

    The com.paydiant.android.net.wifi.PaydiantWifiConfigParser utility class provides functionality to parse contents created through WLW’s Wi-Fi portal.

    The parser returns android.net.wifi.WifiCon figuration objects that can be used to setup the required WLW-supported Wi-Fi networks.

    The methods exposed in the parser utility enable a developer to instantiate the parser as well as perform the actual parsing.

    Constructor

    ItemDescription
    Methodpublic PaydiantWifiConfigParser(ContextWrapper contextWrapper, String wifiConfigProtocol, String wifiConfigHost, String wifiConfigBrandPath, boolean eapEnabled)
    Creates an instance of the WLW Wi-Fi Config Parser using the provided parameters.

    contextWrapper - A reference to the app's android ContextWrapper.
    wifiConfigProtocol, wifiConfigHost and wifiConfigBrandPath - define the configuration's access path, which is created using the WLW Wi-Fi portal.
    eapEnabled - specifies whether or not Wi-Fi configurations supporting the 802.11 EAP standard should be considered.

    Parse configurations

    ItemDescription
    Methodpublic List < WifiConfiguration > parseConfigs()
    Parses the configurations created through the WLW Wi-Fi portal and return a list of android.net.wifi.WifiConfiguration objects that enable the Android Wi-Fi Manager to create the necessary Wi-Fi networks on user devices.

    Location Utility

    The Location Utility tool enables the developer to retrieve the latitude and longitude geo-location of the device for the purpose of populating the mobile wallet’s store locater with data that is relevant to the user’s current location.

    Connecting and Disconnecting the app with the device location client may take a few seconds, so the developer is advised to implement a programmatic delay prior to calling any subsequent methods that are dependent on the service.

    Enable locating

    ItemDescription
    Methodpublic void startLocationUpdationService(Context context);
    Connects the mobile wallet app to the device’s GPS location client. This method must be invoked before the Get Location method can be called.

    Suspend locating

    ItemDescription
    Methodpublic void stopLocationUpdationService(Context context);
    Disconnects the mobile wallet app with the device’s GPS location client and removes the registered listener callbacks. We recommend that you call this method whenever the mobile wallet app is sent to the background in order to optimize the device battery preservation and performance, which can be affected by the app’s continuous effort to update the device location.

    Get location

    ItemDescription
    Methodpublic void getLocation(Context context);
    Returns the current geo-location of the device, provided that the Enable Locating method has been invoked prior to calling this method.

    Payment Account Utility

    The Payment Account Utility tool enables the developer to retrieve and cache a payment account’s reference identification for the purpose of using it for the app’s default autopay account feature.

    Each method exposed in the Payment Account Utility includes two overloaded versions to allow the developer to implement the functionality associated with either the meta-data or non-meta-data based payment account retrieval methods.

    Cache default payment account

    These methods cache the specified payment account as the default payment account in the device.

    Non meta-data

    ItemDescription
    Methodpublic static boolean cacheDefaultPaymentAccount(Context context, PaymentAccount paymentAccount)
    In this overloaded instance of the caching method, the paymentAccount parameter is populated with the non-meta-data object representing the payment account to be cached.

    Meta-data

    ItemDescription
    Methodpublic static boolean cacheDefaultPaymentAccountData(Context context, PaymentAccountData paymentAccountData)
    In this overloaded instance of the caching method, the paymentAccountData parameter is populated by the meta-data object representing the payment account to be cached.

    Retrieve Default Payment Account

    These methods identify and return the cached payment account from the provided list of payment accounts. Since the utility caches the payment account as an identifier only, the list of Payment Accounts available for the user must be provided in order to identify the cached payment account and retrieve its corresponding data.

    Non meta-data

    ItemDescription
    Methodpublic static PaymentAccount retrieveDefaultPaymentAccount (Context context, List < ? extends PaymentAccount > paymentAccounts)
    In this overloaded instance of the caching method, the paymentAccounts parameter is populated with the object containing the array of non-meta-data payment accounts available in the mobile wallet.

    Meta-data

    ItemDescription
    Methodpublic static PaymentAccountData retrieveDefaultPaymentAccountData (Context context, List < ? extends PaymentAccountData > paymentAccountData)
    In this overloaded instance of the caching method, the paymentAccountData parameter is populated with the object containing the array of meta-data payment accounts available in the mobile wallet.

    Clear cached default payment account

    ItemDescription
    Methodpublic static boolean removeCachedDefaultPaymentAccount (Context context)
    Removes the cached default payment account from the mobile wallet device cache.

    Online Ordering Integration

    For mobile wallet providers who enable online ordering through the mobile wallet, WLW provides a mechanism for retrieving recent order history for a particular user for the purpose of streamlining repeat orders.

    Get order summary

    ItemDescription
    UI Methodpublic List < Order > retrieveOrderHistorySummary();

    Retrieves the set of order objects representing orders that have previously been placed for the logged-in user.
    Successpublic void onRetrieveOrderHistorySummarySuccess(List < Order > orderList):
    Failurepublic void onRetrieveOrderHistorySummaryFailure(Paydiant Exception exception);
    Core methodpublic List<order>retrieveOrderHistorySummary();

    Get order detail

    ItemDescription
    UI Method-(void)retrieveOrder:(String orderId)
    Returns detailed information about the particular order specified in the orderId parameter.
    Successpublic void onRetrieveOrderSuccess(Order order):
    Failurepublic void onRetrieveOrderFailure(Paydiant Exception exception);
    Core methodpublic void retrieveorder:(String orderId);

    Set order listener

    ItemDescription
    Set Listenervoid setOrderHistoryServiceListener(IOrderHistoryServiceListener listener);
    Sets com.paydiant.android.ui.service.orderHistory, IOrderHistoryServiceListener or an overridden instance of com.paydiant.android.ui.service.orderHistory.orderHistoryServiceListenerAdapter so callback methods can be invoked during execution of the order integration methods for the UI Package.
    Remove Listenerpublic void removeListender();
    Removes the order integration listener and sets it to null.