Search code examples
javaandroidin-app-billingandroid-billing

Is it possible to get single item SKU details, by single productID?. (Android, IabHelper)


I want to get single SKU details (Not ArrayList) using IabHelper, by putting single productID putString() (not putStringArrayList)

    ...
    final int API_VERSION = 3;
    final String PACKAGE_NAME = mContext.getPackageName();
    Bundle bandleSKU = new Bundle();
    querySkus.putString(GET_SKU_DETAILS_ITEM_LIST, "<someProcuctID>"); 
    Bundle skuDetails = mService.getSkuDetails(API_VERSION, PACKAGE_NAME, type, bandleSKU);

    if (null != skuDetails) {
        int response = skuDetails.getInt(RESPONSE_CODE);
        if (response == BILLING_RESPONSE_RESULT_OK) {
           String response = skuDetails.getString(RESPONSE_GET_SKU_DETAILS_LIST);
         }
    }
   ...

Solution

  • No, this violates the contract of that call. What you should do instead is create a new ArrayList of size 1 and add your product ID there:

    ...
    Bundle bandleSKU = new Bundle();
    ArrayList<String> productIds = new ArrayList<>(1);
    productIds.add("<someProductID>");
    querySkus.putString(GET_SKU_DETAILS_ITEM_LIST, productIds); 
    Bundle skuDetails = mService.getSkuDetails(API_VERSION, PACKAGE_NAME, type, bandleSKU);
    
    if (null != skuDetails) {
        int response = skuDetails.getInt(RESPONSE_CODE);
        if (response == BILLING_RESPONSE_RESULT_OK) {
            ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);
            String productDetailsJson = responseList.get(0);
        }
    }
    ...