I have successfully implemented in app billing into my app which all works fine. I am now trying to retrieve the price of items (set in developer console) so that I can reflect these prices within my app without hard-coding values.
This code quite obviously only gathers prices of the items already purchased through the Inventory which is not what I'm looking for:
SkuDetails gasDetails = inventory.getSkuDetails(SKU_FULL);
if (gasDetails != null){
alert("Gas is " + gasDetails.getPrice());}
I have looked a the docs querying items available for purchase but struggling to understand it. I would of thought that the Helper class would have implemented some sort of get prices method.
So, my question: Can anyone point me in the right direction?
Using the billing api
implementation 'com.android.billingclient:billing:1.1'
Use this to fetch SKU details
public void getPrices(){
List<String> skuList = new ArrayList<> ();
skuList.add("id_one"); //These are the product ids in your google console
skuList.add("id_two");
skuList.add("id_three");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
for (SkuDetails details:
skuDetailsList) {
String item = details.getSku();
String price = details.getPrice();
String description = details.getDescription();
String currencyCode = details.getPriceCurrencyCode();
String title = details.getTitle();
Toast.makeText(InAppBillingActivity.this, "Finished", Toast.LENGTH_SHORT).show();
Log.d("hererereeer- item ", item);
Log.d("hererereeer- price ", price);
Log.d("hererereeer- descr ", description);
Log.d("hererereeer- code ", currencyCode);
Log.d("hererereeer- title ", title);
}
}
});
}
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