Skip to main content
Samsung Developer Program

Retrieving a List of All Items Available in the Service App

Service apps and their users can retrieve a list of all available items currently registered to the Seller Office account of the service app. The following diagram illustrates the query.

OpenIABLibrary_Integration_GeneratingListofAllAvailableCommercialItems_Diagram.png

Getting a list of all items available in the service app
  1. In the Trivial Drive app UI, tap QUERY ITEMS.
  2. This button invokes the method onQueryAvailableButtonClicked() of MainActivity.java, which calls querySkuListAsync() of OpenIabHelper.java.

MainActivity.java
public void onQueryAvailableButtonClicked(View arg0) {
    ...
    mHelper.querySkuListAsync(new IabHelper.QuerySkuListFinishedListener() {
        @Override
        public void onQuerySkuListFinished(IabResult iabResult, List<SkuDetails> list, String s) {
            setWaitScreen(false);
            if (iabResult.isFailure()) {
                complain("Query SKU List failed \n"+iabResult.getMessage());
            } else {
                StringBuilder stringBuilder = new StringBuilder());
                stringBuilder.append("SKU LIST: \n");
                for (int i = 0; i < list.size(); i++) {
                    stringBuilder.append(list.get(i).getTitle() + "\n");
                }
                alert(stringBuilder.toString());
            }
        }
    });
}
  1. querySkuListAsync() queries the available SKUs then returns the available SKUs of the specified type.
 OpenIabHelper.java
 public void querySkuListAsync(@NotNull final IabHelper.QuerySkuListFinishedListener listener) {
     querySkuListAsync(listener, "10");
 }
OpenIabHelper.java
public void querySkuListAsync(@NotNull final IabHelper.QuerySkuListFinishedListener listener, @NotNull final String skuType) {
    checkSetupDone("querySkuListAsync");
    if (listener == null) {
        throw new IllegalArgumentException("Inventory listener must be not null"); 
    }
    new Thread(new Runnable() {
        public void run() {
            IabResult result;
            List<SkuDetails> skuDetails = null;
            try {
                skuDetails = querySkuList(skuType);
                reslut = new IabResult(BILLING_RESPONSE_RESULT_OK, "Sku List refresh successful.");
            } catch (IabException exception) {
                result = exception.getResult();
                Logger.e("querySkuListAsync() Error : ", exception);
            }
            
            final IabResult result_f = result;
            final List<SkuDetails> skuDetails_f = skuDetails;
            handler.post(new Runnable() {
                public void run() {
                    if (setupState == SETUP_RESULT_SUCCESSFUL) {
                        listener.onQuerySkuListFinished(result_f, skuDetails_f, skuType);
                    }
                }
            });
        }
    }).start();
} 
  1. The results of the query are returned in a list of SkuDetails via IabHelper.QuerySkuListFinishedListener.
MainActivity.java
public void onQuerySkuListFinished(IabResult iabResult, List<SkuDetails> list, String s) {
    setWaitScreen(false);
    if (iabResult.isFailure()) {
        complain("Query SKU List failed \n" + iabResult.getMessage());
    } else {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("SKU LIST: \n");
        for (int i = 0; i < list.size(); i++) {
            stringBuilder.append(list.get(i).getTitle()+ "\n");
        }
        alert(stringBuilder.toString());
    }
}); 
  • Was this article helpful?