Created
February 5, 2014 14:19
-
-
Save tanis2000/8824514 to your computer and use it in GitHub Desktop.
Working querySkuDetails for marketbilling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus) | |
throws RemoteException, JSONException { | |
logDebug("Querying SKU details."); | |
ArrayList<String> skuList = new ArrayList<String>(); | |
skuList.addAll(inv.getAllOwnedSkus(itemType)); | |
if (moreSkus != null) { | |
for (String sku : moreSkus) { | |
if (!skuList.contains(sku)) { | |
skuList.add(sku); | |
} | |
} | |
} | |
if (skuList.size() == 0) { | |
logDebug("queryPrices: nothing to do because there are no SKUs."); | |
return BILLING_RESPONSE_RESULT_OK; | |
} | |
// Split the sku list in blocks of no more than 20 elements. | |
ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>(); | |
ArrayList<String> tempList; | |
int n = skuList.size() / 20; | |
int mod = skuList.size() % 20; | |
for (int i = 0 ; i < n ; i++) { | |
tempList = new ArrayList<String>(); | |
for (String s : skuList.subList(i*20, i*20+20)) { | |
tempList.add(s); | |
} | |
packs.add(tempList); | |
} | |
if (mod != 0) { | |
tempList = new ArrayList<String>(); | |
for (String s : skuList.subList(n*20, n*20+mod)) { | |
tempList.add(s); | |
} | |
packs.add(tempList); | |
} | |
for (ArrayList<String> skuPartList : packs) { | |
Bundle querySkus = new Bundle(); | |
querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList); | |
Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), | |
itemType, querySkus); | |
if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) { | |
int response = getResponseCodeFromBundle(skuDetails); | |
if (response != BILLING_RESPONSE_RESULT_OK) { | |
logDebug("getSkuDetails() failed: " + getResponseDesc(response)); | |
return response; | |
} | |
else { | |
logError("getSkuDetails() returned a bundle with neither an error nor a detail list."); | |
return IABHELPER_BAD_RESPONSE; | |
} | |
} | |
ArrayList<String> responseList = skuDetails.getStringArrayList( | |
RESPONSE_GET_SKU_DETAILS_LIST); | |
for (String thisResponse : responseList) { | |
SkuDetails d = new SkuDetails(itemType, thisResponse); | |
logDebug("Got sku details: " + d); | |
inv.addSkuDetails(d); | |
} | |
} | |
return BILLING_RESPONSE_RESULT_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment