本文整理汇总了Java中com.android.vending.billing.IInAppBillingService.getSkuDetails方法的典型用法代码示例。如果您正苦于以下问题:Java IInAppBillingService.getSkuDetails方法的具体用法?Java IInAppBillingService.getSkuDetails怎么用?Java IInAppBillingService.getSkuDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.vending.billing.IInAppBillingService
的用法示例。
在下文中一共展示了IInAppBillingService.getSkuDetails方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.android.vending.billing.IInAppBillingService; //导入方法依赖的package包/类
/**
* In your application, you can query the item details from Google Play using the In-app Billing Version 3 API.
* To pass a request to the In-app Billing service, first create a Bundle that contains
* a String ArrayList of product IDs with key "ITEM_ID_LIST",
* where each string is a product ID for an purchasable item.
* See https://developer.android.com/google/play/billing/billing_integrate.html#QueryDetails
*
* @param service in-app billing service
* @param itemType "inapp" or "subs"
* @param itemIds contains the list of item ids that you want to request
* @return
* @throws BillingException
*/
ItemDetails get(IInAppBillingService service,
String itemType,
ArrayList<String> itemIds) throws BillingException {
ItemDetails itemDetails = new ItemDetails();
List<ArrayList<String>> splitItemIdList = new ArrayList<>();
// There reason why it splits the item ids per request
// It's because there is a known bug on Google Api
// https://code.google.com/archive/p/marketbilling/issues/137
for (int i = 0; i < itemIds.size(); i += ItemGetter.MAX_SKU_PER_REQUEST) {
int fromIndex = i;
int toIndex = Math.min(itemIds.size(), i + ItemGetter.MAX_SKU_PER_REQUEST);
ArrayList<String> list = new ArrayList<>(itemIds.subList(fromIndex, toIndex));
splitItemIdList.add(list);
}
for (ArrayList<String> splitItemIds : splitItemIdList) {
try {
Bundle itemIdsBundle = createBundleItemListFromArray(splitItemIds);
Bundle skuDetails = service.getSkuDetails(mApiVersion, mPackageName, itemType, itemIdsBundle);
List<String> detailList = getItemsFromResponse(skuDetails);
putAll(detailList, itemDetails);
} catch (RemoteException e) {
throw new BillingException(Constants.ERROR_REMOTE_EXCEPTION, e.getMessage());
}
}
return itemDetails;
}
示例2: start
import com.android.vending.billing.IInAppBillingService; //导入方法依赖的package包/类
@Override
void start(@Nonnull IInAppBillingService service, int apiVersion, @Nonnull String packageName) throws RemoteException, RequestException {
final Bundle skusBundle = new Bundle();
skusBundle.putStringArrayList("ITEM_ID_LIST", skus);
final Bundle bundle = service.getSkuDetails(apiVersion, packageName, product, skusBundle);
if (!handleError(bundle)) {
onSuccess(Skus.fromBundle(bundle, product));
}
}
示例3: getSkuDetails
import com.android.vending.billing.IInAppBillingService; //导入方法依赖的package包/类
/**
* Wraps {@link IInAppBillingService#getSkuDetails(int, String, String, Bundle)}.
*
* @param skus SKUs to load details for.
*
* @return Bundle containing requested SKUs details. Can be null.
*/
@Nullable
Bundle getSkuDetails(@NonNull final Collection<String> skus) {
OPFLog.logMethod(Arrays.toString(skus.toArray()));
final IInAppBillingService service = getService();
if (service == null) {
return null;
}
final List<String> skuList = new ArrayList<>(skus);
final Bundle result = new Bundle();
try {
final int size = skuList.size();
final int batchCount = size / BATCH_SIZE;
for (int i = 0; i <= batchCount; i++) {
final int first = i * BATCH_SIZE;
final int last = Math.min((i + 1) * BATCH_SIZE, size);
final ArrayList<String> batch = new ArrayList<>(skuList.subList(first, last));
final Bundle bundle = GoogleUtils.putSkuList(new Bundle(), batch);
for (final ItemType itemType : ItemType.values()) {
final String type = itemType.toString();
final Bundle details = service.getSkuDetails(API, packageName, type, bundle);
final Response response = GoogleUtils.getResponse(details);
OPFLog.d("From %d to %d. Type: %s. Response: %s. Details: %s.",
first, last, itemType, response, OPFUtils.toString(details));
if (response != Response.OK) {
// Return received bundle if error is encountered
return details;
} else {
// Aggregate all loaded details in a single bundle
final ArrayList<String> skuDetails = GoogleUtils.getSkuDetails(details);
GoogleUtils.addSkuDetails(result, skuDetails);
}
}
}
} catch (RemoteException exception) {
OPFLog.e("getSkuDetails request failed.", exception);
return null;
}
return GoogleUtils.putResponse(result, Response.OK);
}
示例4: querySkuDetails
import com.android.vending.billing.IInAppBillingService; //导入方法依赖的package包/类
int querySkuDetails(final Inventory inv, final String[] moreSkus) throws RemoteException, JSONException {
final ArrayList<String> skuList = new ArrayList<String>();
skuList.addAll(inv.getAllOwnedSkus(ITEM_TYPE_INAPP));
if (moreSkus != null)
skuList.addAll(Arrays.asList(moreSkus));
if (skuList.size() == 0)
return 0;
final Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
final IInAppBillingService service = mBillingService.get();
if (service == null) {
Log.w(DonateActivity.class.getSimpleName(), "SkuDetails: Billing service is null");
return -1;
}
final Bundle skuDetails = service.getSkuDetails(3, getPackageName(), ITEM_TYPE_INAPP, querySkus);
if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
final int response = getResponseCodeFromBundle(skuDetails);
if (response != 0) {
Log.e(DonateActivity.class.getSimpleName(), "SkuDetails: Bad response " + response);
// EasyTracker.getTracker().sendEvent("Donate", "SkuDetails bad response " + response, "", -1L);
return response;
}
return -1;
}
final ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);
for (final String thisResponse : responseList) {
final SkuDetails d = new SkuDetails(ITEM_TYPE_INAPP, thisResponse);
inv.addSkuDetails(d);
}
return 0;
}