Android

Quick Start Instructions

Minimum Requirements

Minimum Android version supported by the SDK is 7.0

Installation

Installation is as easy as adding the SDK file to your project. The steps for Android are as follows:

Step 1 - Copy the aar file to the application folder and add it as a dependency:

In your project’s build.gradle, add the following line under the dependencies section:

dependencies {
	compile files('com.anywherecommerce.android.sdk-release.aar)
}

Note that the SDK makes use of common libraries like Retrofit and GSON. If you encounter dex issues, please exclude the duplicated modules. For example, to exclude the GSON library:

compile('com.anywherecommerce.android.sdk.jar’) {
    exclude module: 'gson'
}

For reference, here is a list of project dependencies in the SDK:

com.squareup.retrofit2:converter-gson:2.3.0'
com.squareup.retrofit2:converter-simplexml:2.3.0
com.squareup.okhttp3:logging-interceptor:3.8.0
com.googlecode.libphonenumber:libphonenumber:8.5.0

Step 2 - Go to the AndroidManifest.xml and set these permissions.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Then, add the following line to the AndroidManifest.xml under the application tag:

<service   	 android:name="com.anywherecommerce.android.sdk.services.CardReaderConnectionService"
    android:stopWithTask="false" />

Step 3 – Initialize the SDK

Call the following method with your terminal ID and secret provided by AnywhereCommerce.

SDKManager.initialize(this, new AnyPayTerminal("ee455f50", "password"));

Step 3- Request Permissions

As of Android 6.0, certain permissions cannot be assigned programmatically and must be granted at runtime. A convenient class called PermissionController has been added to help simplify this process.

public static boolean verifyAppPermissions(Activity activity)

Step 4 - Authenticate the Terminal

(Mandatory for the AnyPay default terminal. Optional if you are using your own). Initialize the terminal to activate it and apply the local configuration. For the AnyPay terminal, it will automatically sync the configuration with the server.

Terminal.getInstance().authenticate(new AuthenticationListener() {
    @Override
    public void onAuthenticationComplete() {
        addText("Terminal Authenticated Successfully");
    }

    @Override
    public void onAuthenticationFailed(MeaningfulError error) {
        addText("Terminal Authentication Failed");
    }
});