當前位置: 首頁>>代碼示例>>Java>>正文


Java IInAppBillingService.getSkuDetails方法代碼示例

本文整理匯總了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;
}
 
開發者ID:alessandrojp,項目名稱:android-easy-checkout,代碼行數:45,代碼來源:ItemGetter.java

示例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));
	}
}
 
開發者ID:xu6148152,項目名稱:binea_project_for_android,代碼行數:10,代碼來源:GetSkuDetailsRequest.java

示例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);
}
 
開發者ID:onepf,項目名稱:OPFIab,代碼行數:47,代碼來源:GoogleBillingHelper.java

示例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;
}
 
開發者ID:ianhanniballake,項目名稱:LocalStorage,代碼行數:32,代碼來源:DonateActivity.java


注:本文中的com.android.vending.billing.IInAppBillingService.getSkuDetails方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。