I am trying to implement in-app purchases using the latest Google Play Billing Library (2.0.1)
• I've Added product Ids to the skuList and in the Google Play Console after publishing apk in Internal App Testing
• But when I launch billingFlow I get the following
2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Other code5
2019-07-01 13:17:02.436 1225-1225/com.mypackage.myapp D/InAppBilling: Invalid SKU input params. SKU can't be null
Here's my code:
List skuList = new ArrayList<>();
skuList.add("product_1");
skuList.add("product_2");
skuList.add("product_3");
skuList.add("product_"4);
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
&& skuDetailsList != null) {
for (Object skuDetailsObject : skuDetailsList) {
skuDetails = (SkuDetails) skuDetailsObject;
String sku = skuDetails.getSku();
String price = skuDetails.getPrice();
if ("product_1".equals(sku)) {
textA.setText(price);
} else if ("product_2".equals(sku)) {
textB.setText(price);
} else if ("product_3".equals(sku)) {
textC.setText(price);
} else if ("product_4".equals(sku)) {
textD.setText(price);
}
} else {
Log.d(TAG, "Sku is null");
}
Log.d(TAG, "i got response");
Log.d(TAG, String.valueOf(billingResult.getResponseCode()));
Log.d(TAG, billingResult.getDebugMessage());
}
});
mBuyButton = findViewById(R.id.pay);
mBuyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build();
mBillingClient.launchBillingFlow(PayActivity.this, flowParams);
}
});
and here's the logcat
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Sku is null
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: i got response
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: -1 //billing result response code
2019-07-01 13:17:04.173 1225-1225/com.mypackage.myapp D/InAppBilling: Service connection is disconnected. //debug message
I have also tried with reserved test product ids android.test.purchase but same error
I have also uploaded app on Play Console (internal testing) but it didn't work from there too
Any help is appreciated...
EDIT: After lots of experiments I found that Billing Service is being disconnected but the reason is not as below https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse#service_disconnected (-1)
mBillingClient = BillingClient.newBuilder(PayActivity.this).setListener(this).enablePendingPurchases().build();
mBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
Log.d(TAG, "Connection finished");
}
@Override
public void onBillingServiceDisconnected() {
//TODO implement your own retry policy
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
mBillingClient.startConnection(this);
}
});
and after getting response onBillingSetupFinished is being called
Issue solved it by moving my app to alpha testing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With