我想通过使用单个productID putString()(而非putStringArrayList)来使用IabHelper获得单个SKU详细信息(而非ArrayList)。
...
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);
}
}
...
最佳答案
不,这违反了该通话合同。您应该做的是创建一个新的ArrayList
大小为1的产品,并在其中添加产品ID:
...
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);
}
}
...