This article describes how to set up the Payment Links SDK for Android.
Requirements
Step 1 | Import the SDK
To import the Android Payment Links SDK, add the following implementation to your build.gradle file:
implementation("com.appcharge:android-payment-links:1.5.0")
Then add the following to your settings.gradle file:
repositories {
mavenCentral()
}
Step 2 | Add Permissions
In the Manifest file, add the necessary permissions to access the network state and enable incoming deeplink over HTTPS:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
Next, add support for checkout activity and deeplink scheme:
<activity
android:name="com.appcharge.paymentlinks.CheckoutActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="unspecified"
android:exported="true"
android:launchMode="singleTask"
tools:ignore="DiscouragedApi">
<!-- Custom scheme -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="acnative-{IDENTIFIER}"/>
<data android:host="action"/>
<data android:scheme="https"/>
</intent-filter>
</activity>
The intent-filter includes a scheme "acnative-{IDENTIFIER}". Change the {IDENTIFIER} to the last sequence of your package name. For example, if your package name is com.appcharge.mysupergame, the identifier will be mysupergame.This name must be lowercase with no spaces, according to the Android code style guide.
Step 4 | Set up foreground service for your checkout (Optional)
To improve checkout stability, you can enable a foreground service. This keeps your app prioritized while the checkout is open, helping prevent Android from closing or deprioritizing it during payment and network operations.
To set up the foreground service:
- Add the following permissions to your
AndroidManifest.xml file:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
- Then register the service inside the
<application> tag:
<application>
<service android:name="com.appcharge.paymentlinks.CheckoutService"
android:exported="false"
android:foregroundServiceType="dataSync" />
</application>
- After SDK initialization or before launching checkout, enable or disable the service in code:
BridgeAPI.setCheckoutServiceMode(true) // Enable
BridgeAPI.setCheckoutServiceMode(false) // Disable
By default, setCheckoutServiceMode is enabled. If you don’t want to use the foreground service, remove the related permissions and the CheckoutService declaration from your manifest file, or disable it using the SDK Bridge method above.