Question

I found the following code from here to get products list from google play store

ArrayList skuList = new ArrayList();
skuList.add("premiumUpgrade");
skuList.add("gas");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList(“ITEM_ID_LIST”, skuList);

is there a way to get dynamic products list? here its hard coded.what happens when i add new products after app launch?

Was it helpful?

Solution

This is not currently possible using Google API.

Create a JSON file that contains current SKUs and place it on some server.

In your app, first load this file from server URL and then use this list of SKUs to retrieve product details via Google API.

To Google: Provide function for this, SHAME ON YOU!

OTHER TIPS

If you don't want to implement the logic to acquire the product list from your own server, another option would be to use pre-defined "dummy" product ids, like product id slots:

private static final String[] PRODUCTIDS = {"product1", "product2", "product3", etc. };

The getSkuDetails function will simply return null for non-existing product ids. So if you don't expect your product list to vary too often or too much, then you could just define a small number of product ids in your app, and skip null values returned by getSkuDetails.

If you want to add a new product, just use the id defined by the next unused slot in the developer console, and your app will list it without updating the app.

Deleting a product can be tricky, because inactive and deleted product ids will still be returned, so you could mark a product deleted using its description field - use a pre-defined constant, like "NOT AVAILABLE" and check for its presence in your app. If a product description equals to this constant, simply skip it and don't list it.

I know, I know. It's a dirty hack. But it works.

It is not possible for a reason. If you were able to fetch the updated inapp product list how would you be able to serve those new products without changing the app code? If you change the product list then you have to release an update for the app that deals with the new products.

The only reason to fetch new products without changing the app code would be to change prices for the products themselves but that would mean going against the Google terms & conditions

This is now possible using the Inappproducts: list API:

List all the in-app products for an Android app, both subscriptions and managed in-app products.

Also, read about Authorization which is needed for making use of above API.

One way you can do this is to create a copy of all your product IDs in a database (like Firebase DB), query these IDs in your app and add them to a String list. Then finally pass this list to the SkuDetailsParams setSkusList() method:

SkuDetailsParams params = SkuDetailsParams.newBuilder()
                        .setType(INAPP)
                        .setSkusList(skuList) //pass the list there
                        .build();

I guess, the simplest way is to use Firebase Remote Config, where skuList will be updated automatically once published to all devices.

Check Remote Config for implementation: https://firebase.google.com/docs/remote-config/use-cases

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top