Migrate from Google Play Billing to Appstore SDK
Use this guide to migrate your app from Google Play Billing to the Appstore SDK In-App Purchasing (IAP) API. To review other porting solutions, see Migrate from Google Play Billing.
- Migrate to the Appstore SDK
- Step 1. Download and configure Appstore SDK
- Step 2. Configure your AndroidManifest.xml file
- Step 3. Implement logic to mediate between Google Play Billing and IAP
- Step 4. Add and implement the Appstore SDK IAP API
- Step 5. Test your app
Migrate to the Appstore SDK
To migrate from Google Play Billing to the Appstore SDK, follow these instructions.
- Download and configure the Appstore SDK.
- Configure your AndroidManifest.xml file to support Appstore SDK IAP.
- In your app, implement logic to mediate between Google Play Billing and IAP.
- Add and implement the Appstore SDK IAP API.
- Test your app.
The following sections guide you through these steps.
Step 1. Download and configure Appstore SDK
Download the Appstore SDK here:
To configure the Appstore SDK for your app, follow the instructions in Integrate the Appstore SDK.
Step 2. Configure your AndroidManifest.xml file
Configure your AndroidManifest.xml file to define the IAP ResponseReceiver
for your app. The IAP ResponseReceiver
ensures that the intent communication from the Amazon Client is intercepted by your app. If you are supporting both Google Play Billing and Amazon IAP, you don't need to remove elements related to Google Play Billing; they will simply be ignored by IAP.
In your AndroidManifest.xml file, add the appropriate <receiver>
tag for the IAP ResponseReceiver
. If your app targets Android 12 or higher, you must explicitly set android:exported
to true
in the MainActivity
and ResponseReceiver
as shown in the following example.
<application>
...
<activity android:name="com.amazon.sample.iap.entitlement.MainActivity"
android:label="@string/app_name" android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.amazon.device.iap.ResponseReceiver" android:exported="true"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" >
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY" />
</intent-filter>
</receiver>
</application>
Step 3. Implement logic to mediate between Google Play Billing and IAP
You can use the same code base for your app, regardless of where your app is hosted. Just add logic to your app to determine whether the app was downloaded from the Amazon Appstore or from Google Play. Depending on where the user downloaded the app, run the appropriate methods for either IAP or Google Play Billing.
The following example code determines whether a package was installed from Google Play or the Amazon Appstore:
PackageManager pkgManager = context.getPackageManager();
try {
String installerPackageName = pkgManager.getInstallSourceInfo(context.getPackageName()).getInstallingPackageName();
} catch (PackageManager.NameNotFoundException e) {
// Handle exception
}
if (installerPackageName.startsWith("com.amazon")) {
// Amazon
} else if ("com.android.vending".equals(installerPackageName)) {
// Google Play
}
Step 4. Add and implement the Appstore SDK IAP API
For the most part, Appstore SDK IAP works similarly to Google Play Billing. When you create the path in your code to implement the IAP API, you should be able to use a similar logic flow to Google Play, but will need to account for different class and method names.
The following table maps the most frequently used IAP methods to their Google Play equivalents:
PurchasingService method | PurchasingListener callback | Response object | Google Play Equivalent |
getUserData() |
onUserDataResponse() |
UserDataResponse |
N/A |
getPurchaseUpdates() |
onPurchaseUpdatesResponse() |
PurchaseUpdatesResponse |
queryPurchases() |
getProductData() |
onProductDataResponse() |
ProductDataResponse |
getSkuDetails() |
purchase() |
onPurchaseResponse() |
PurchaseResponse |
launchBillingFlow() |
notifyFulfillment() |
N/A | N/A | consumeAsync() |
Step 5. Test your app
Download and install the App Tester tool to test your Appstore SDK-integrated app. Follow the instructions and links in Testing In-App Purchasing (IAP) to install and use App Tester.
After testing your app locally, you can use the Live App Testing service to beta test your app in a live production environment with a select group of users.
Last updated: May 22, 2024