com.android.billingclient.api.SkuDetailsParams Java Examples

The following examples show how to use com.android.billingclient.api.SkuDetailsParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void querySkus(List<String> query) {
    Log.i("IAB query SKUs");
    SkuDetailsParams.Builder builder = SkuDetailsParams.newBuilder();
    builder.setSkusList(query);
    builder.setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(builder.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult result, List<SkuDetails> skuDetailsList) {
                    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                        for (SkuDetails skuDetail : skuDetailsList) {
                            Log.i("IAB SKU detail=" + skuDetail);
                            skuDetails.put(skuDetail.getSku(), skuDetail);
                            for (IBillingListener listener : listeners)
                                listener.onSkuDetails(skuDetail.getSku(), skuDetail.getPrice());
                        }
                    } else
                        reportError(result, "IAB query SKUs");
                }
            });
}
 
Example #2
Source File: DefaultBillingManager.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
private void loadProducts() {
    List<String> skuList = new ArrayList<>();
    skuList.add(SKU_DONATION);

    SkuDetailsParams params = SkuDetailsParams.newBuilder()
            .setSkusList(skuList)
            .setType(BillingClient.SkuType.INAPP)
            .build();

    mBillingClient.querySkuDetailsAsync(params, (billingResult, skuDetailsList) -> {
        if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
            Log.d(TAG, String.format("Unable to query sku details: %d - %s", billingResult.getResponseCode(), billingResult.getDebugMessage()));
            return;
        }

        ArrayList<BillingProduct> products = new ArrayList<>(skuDetailsList.size());
        for (SkuDetails skuDetails : skuDetailsList)
            products.add(new SkuDetailsBillingProduct(skuDetails));

        mAllProducts.setValue(products);
        invalidateProductsPurchaseStatus();
    });
}
 
Example #3
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
                    .setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams,
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode,
                                List<SkuDetails> skuDetailsList) {
                            listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                        }
                    });
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #4
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
                    .setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams,
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(@NonNull BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                            listener.onSkuDetailsResponse(billingResult, skuDetailsList);
                        }
                    });
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #5
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void querySkuList(final List<String> skuList) {
    Runnable queryRequest = () -> {
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
        mBillingClient.querySkuDetailsAsync(params.build(),
                (billingResult, list) -> {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
                            && list != null) {
                        mSkuDetails = new HashMap<>();
                        for (SkuDetails skuDetails : list) {
                            mSkuDetails.put(skuDetails.getSku().toLowerCase(Locale.ROOT), skuDetails);
                        }
                    }
                });
    };
    executeServiceRequest(queryRequest);
}
 
Example #6
Source File: PlayBillingWrapper.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public void querySkuDetails(List<String> skus) {
    SkuDetailsParams params = SkuDetailsParams
            .newBuilder()
            .setSkusList(skus)
            .setType(BillingClient.SkuType.INAPP)
            .build();

    mClient.querySkuDetailsAsync(params, (billingResult, list) -> {
        // TODO: Check result
        mSkuDetailsList = list;
        mListener.onGotSkuDetails();
    });
}
 
Example #7
Source File: BillingManager.java    From SchoolQuest with GNU General Public License v3.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList,
                                 final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList).
            setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams, new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            listener.onSkuDetailsResponse(responseCode, skuDetailsList);
        }
    });
}
 
Example #8
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void querySkuDetails() {

        if (!billingServiceConnected) {
            mBillingClient.startConnection(this);
            return;
        }

        SkuDetailsParams.Builder skuDetailsParamsBuilder = SkuDetailsParams.newBuilder();
        List<String> skuList = new ArrayList<>();
        skuList.add(mSkuId);
        skuDetailsParamsBuilder.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);

        mBillingClient.querySkuDetailsAsync(skuDetailsParamsBuilder.build(), new SkuDetailsResponseListener() {
            @Override
            public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    if (!skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);
                        }
                    } else {
                        Log.w(LOG_TAG, "Query SKU details is OK, but SKU list is empty " + billingResult.getDebugMessage());


                    }

                } else {
                    Log.w(LOG_TAG, "Query SKU details warning " + billingResult.getResponseCode() + " " + billingResult.getDebugMessage());
                }
            }
        });
    }
 
Example #9
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchProducts(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.INAPP)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch products!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #10
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchSubscriptions(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.SUBS)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch Subscriptions!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #11
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public void donate(@NonNull Activity activity, boolean wasWaiting) {
    if (!wasWaiting)
        listener.showDialog(DialogUtils.progressDialog(activity, R.string.connectingBillingService));

    if (billingClient != null && billingClient.isReady()) {
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(products).setType(BillingClient.SkuType.INAPP);
        billingClient.querySkuDetailsAsync(params.build(), (billingResult, skuDetailsList) -> {
            listener.dismissDialog();

            if (billingResult.getResponseCode() == BillingResponseCode.OK)
                showDonateDialog(activity, skuDetailsList);
            else
                handleBillingErrors(billingResult.getResponseCode());
        });
    } else {
        new Thread() {
            @Override
            public void run() {
                synchronized (billingReady) {
                    try {
                        billingReady.wait();
                        donate(activity, true);
                    } catch (InterruptedException ex) {
                        Log.w(TAG, ex);
                    }
                }
            }
        }.start();
    }
}
 
Example #12
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
            .setSkusList(skuList).setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode,
                                                 List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #13
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList)
            .setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #14
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList, final SkuDetailsResponseListener listener) {
    SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
            .setSkusList(skuList).setType(itemType).build();
    mBillingClient.querySkuDetailsAsync(skuDetailsParams,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode,
                                                 List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
}
 
Example #15
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
public void loadSKUs(){
    List<String> skuList = new ArrayList<>();
    skuList.add("upgrade");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult billingResult,
                                                 List<SkuDetails> skuDetailsList) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            if (skuDetails.getSku().equals("upgrade")){
                                findViewById(R.id.upgrade_button).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        BillingFlowParams billingFlowParams = BillingFlowParams
                                                .newBuilder()
                                                .setSkuDetails(skuDetails)
                                                .build();
                                        billingClient.launchBillingFlow(PictureInPictureUpgradeActivity.this, billingFlowParams);
                                    }
                                });
                            }

                        }
                    }
                }
            });
}
 
Example #16
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public void getSkuDetails(@SkuType String itemType, @NonNull List<String> skus,
                          @NonNull SkuDetailsResponseListener listener) {
    throwIfUnavailable();

    logSafely("Query for SKU details with type: " + itemType + " SKUs: " + TextUtils.join(",", skus));

    SkuDetailsParams query = SkuDetailsParams.newBuilder()
            .setSkusList(skus)
            .setType(itemType)
            .build();
    billing.querySkuDetailsAsync(query, listener);
}