I'm trying retrieve a list (just one item) of available purchases using the Android BillingClient 2.1 as described here. Like this:
private suspend fun querySkuDetails() {
val skuList = ArrayList<String>()
skuList.add("premium_upgrade")
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP)
val skuDetailsResult = withContext(Dispatchers.IO) {
billingClient.querySkuDetails(params.build())
}
if (skuDetailsResult.billingResult.responseCode == BillingClient.BillingResponseCode.OK && skuDetailsResult.skuDetailsList != null) {
for (skuDetails in skuDetailsResult.skuDetailsList as List<SkuDetails>) {
val sku = skuDetails.sku
val price = skuDetails.price
if ("premium_upgrade" == sku) {
premiumUpgradePrice = price
}
}
}
}
In the play store console I have uploaded the app prepared the store page and added a managed product called "premium_upgrade". But I have not yet published the app, as its missing this vital part.
For some reason skuDetailsResult.skuDetailsList
is always returned empty. There is no debugMessage
in billingResult
. So I'm a bit stuck. Any suggestions?
After a bit of searching I found the testing part further down in the left hand menu. https://developer.android.com/google/play/billing/billing_testing
When testing locally I had to change the sku product id to one of of the reserved google ids. So for testing I had to change premium_upgrade
to android.test.purchased
then you can try the entire flow.
Once you have made a test purchase of a manage product it will say that you already own the product and you get kind of blocked there. If you need to re-test the purchase you can use this adb command the clear the purchase history and run it again.
adb shell pm clear com.android.vending