Google in app purchasing get products list
Asked Answered
F

6

11

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?

Fritts answered 14/5, 2013 at 16:11 Comment(3)
Any update about this?Izzo
Any update in 2019?Costanza
Here's a workaround: https://mcmap.net/q/956864/-google-in-app-purchasing-get-products-listGrogram
L
33

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!

Londoner answered 14/5, 2013 at 16:35 Comment(3)
Not available yet, till now Oct 16 '15. Shame on you, google, and apple too . lolEkaterina
@Dinh, please give me the link to the reference, cannot find it.Londoner
developer.apple.com/library/ios/documentation/… There’s no runtime mechanism to fetch a list of all products configured in iTunes Connect for a particular app. You’re responsible for managing your app’s list of products and providing that information to your app. If you need to manage a large number of products, consider using the bulk XML upload/download feature in iTunes Connect.Ekaterina
W
6

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.

Widner answered 27/4, 2014 at 11:42 Comment(1)
If you are using the helper classes from the example Google project then you can query the products by calling IabHelper.queryInventoryAsync(final boolean querySkuDetails, final List<String> moreSkus, final QueryInventoryFinishedListener listener) (or the synchronous version if you prefer), just specify the list of SKUs as the mystic moreSkus parameter. You need to get the previously purchased products anyway, so it is hard to avoid this call. Still ugly to put it mildly.Neurilemma
S
1

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

Shawnna answered 29/10, 2017 at 14:49 Comment(1)
Handling should be left to developers. Many developers handle in-app functionality serverside. And BTW it's not Google's concern.Pedicab
C
1

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.

Considered answered 12/3, 2019 at 7:39 Comment(0)
G
0

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();
Grogram answered 3/4, 2021 at 6:44 Comment(0)
I
0

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

Intervocalic answered 30/7, 2021 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.