Build on Android

Applies to: Point of Sale API - Android

Learn how to open the Square Point of Sale application from your mobile Android application to process in-person payments using Square hardware.

Link to section

Requirements and limitations

  • You've read the introductory review of this API.
  • You need a valid access token. You should test with Sandbox credentials whenever possible. For more information, see Access Tokens and Other Square Credentials.
  • You're building an Android application - For information about building an iOS application, see Build on iOS. For information about building a Mobile Web application, see Build on Mobile Web.
  • You're using the Point of Sale SDK for Android version 2.0 and the Square Point of Sale application v4.64 and later - The Point of Sale SDK provides a helpful wrapper around the Point of Sale API, which simplifies the development process.
  • You're using version 15 as the minimum supported Android SDK version - If you're using an earlier version, you might need to update your SDK to use the sample code in this topic.
  • You're using Java - The Point of Sale SDK only supports Java on Android.
Link to section

1. Install the Square Point of Sale application

You should install the latest version of the Square Point of Sale application from the Google Play Store.

If you choose to use an older version of the Point of Sale application, you need to confirm that the version is compatible with the Android Point of Sale SDK version you're using.

Application versionAndroid SDK version
4.64 and laterv2.0
4.48 and laterv1.
4.41 and laterv1.0

There are two ways to determine the current version of the Square Point of Sale application:

  • Look it up in the device settings.

  • Run the following command using ADB:

    adb shell dumpsys package com.squareup | grep versionName
Link to section

2. Register your application

The Square Point of Sale application for Android only accepts requests if it can authenticate the source of the request. Square uses the following information to authenticate application requests:

  • SHA-1 fingerprint - The Square Point of Sale application uses the SHA-1 fingerprint of an application to validate the source of incoming requests.
  • Package name (such as com.example.myapp) - A Java-language-style package name for your Android application. This needs to match the name you use in the package attribute in the Android manifest for your application.

To register your application:

  1. Obtain your Android application fingerprint.
  2. Open the Developer Dashboard.
  3. In the left pane, choose Point of Sale API.
  4. In the Android section, choose Add a new Android Package.
  5. Enter your package name and fingerprint.
  6. Choose Save.
Link to section

3. Add the Square Point of Sale SDK to your project

Link to section

Install the Point of Sale SDK manually

To install the Point of Sale SDK manually, download the point-of-sale-android-sdk repo in GitHub.

Link to section

Add the Point of Sale SDK to a Gradle project

If you develop with Gradle, add the following dependency that is appropriate for your plugin to your build.gradle file and rebuild your project.

Link to section

Android plugin for Gradle 3.0.0 and later

dependencies { implementation 'com.squareup.sdk:point-of-sale-sdk:2.+' }
Link to section

Android plugin for Gradle 2 and later

dependencies { compile 'com.squareup.sdk:point-of-sale-sdk:2.+' }
Link to section

Add the Point of Sale SDK to a Maven project

If you develop with Maven, add the following dependency to your pom.xml file and rebuild your project:

<dependency> <groupId>com.squareup.sdk</groupId> <artifactId>point-of-sale-sdk</artifactId> <version>2.0</version> <type>aar</type> </dependency>
Link to section

4. Update your project AndroidManifest

If your project targets Android 11 or newer, you must add the following object to your manifest:

<queries> <package android:name="com.squareup" /> </queries>
Link to section

5. Add code to initiate a transaction from your application

  1. Set your application ID. To find your application ID, open the Developer Dashboard, and choose an application.
  2. Add a constructor that configures an instance of PosClient.
  3. Add code that creates a new charge request and uses it to initiate a transaction in the Point of Sale application. The following function uses ChargeRequest.Builder to create a charge for $1 USD and then uses that request to create a ChargeRequest and initiate the transaction with an Intent object.

Set your application ID as shown:

private static final String APPLICATION_ID = "{REPLACE ME}";

Add a constructor as shown:

public class MainActivity extends Activity { private PosClient posClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); // Replace APPLICATION_ID with a Square-assigned application ID posClient = PosSdk.createClient(this, APPLICATION_ID); } }

Create a new charge request as shown:


The AlertDialogHelper object that is used in the step 4 and step 5 code blocks is an example of a helper class instance and not part of the Point of Sale SDK.

Link to section

6. Add code to receive data from the Square Point of Sale application

When the Square Point of Sale application completes a transaction (or encounters an error), it returns the UI focus to your application and calls the onActivityResult() method of the activity that initiated the transaction. Add code to parse the response.

For more information about the ChargeRequest class, see the Android Point of Sale API Technical Reference.

Did you know?

Your application should keep track of whether a Point of Sale API request has been issued and whether a callback has been received. Because of the constraints of application-switching APIs, sellers can leave Square Point of Sale during an API request and return to your application. It's your responsibility to direct them to return to Square and finish the transaction.

Link to section

7. Test your code

  1. Sign in to the Square Point of Sale application with the business location that you want to use to accept payments.
  2. Open your application and initiate a transaction.
  3. Test your callbacks:
    • Test the cancellation callback by canceling a transaction.
    • Test the success callback by completing a cash transaction.

The Sandbox doesn't support credit card testing for mobile. For alternatives, see Testing for supported countries.

Link to section

See also