Search in sources :

Example 6 with SkuDetailsResponseListener

use of com.android.billingclient.api.SkuDetailsResponseListener in project PhoneProfiles by henrichg.

the class DonationFragment method updateGUIAfterBillingConnected.

public void updateGUIAfterBillingConnected() {
    // Start querying for SKUs
    PPApplication.logE(TAG, "handleManagerAndUiReady");
    final List<String> inAppSkus = mBillingProvider.getBillingManager().getSkus(/*!mDebug, */
    BillingClient.SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(BillingClient.SkuType.INAPP, inAppSkus, new SkuDetailsResponseListener() {

        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            PPApplication.logE(TAG, "onSkuDetailsResponse responseCode=" + responseCode);
            String[] prices = new String[] { "1 €", "2 €", "3 €", "5 €", "8 €", "13 €", "20 €" };
            if (skuDetailsList != null)
                PPApplication.logE(TAG, "onSkuDetailsResponse skuDetailsList=" + skuDetailsList.size());
            if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
                if (skuDetailsList.size() > 0) {
                    SKU_DETAILS = new ArrayList<>();
                    for (int i = 0; i < inAppSkus.size(); i++) {
                        for (int j = 0; j < skuDetailsList.size(); j++) {
                            if (skuDetailsList.get(j).getSku().equals(inAppSkus.get(i))) {
                                PPApplication.logE(TAG, "Found sku: " + skuDetailsList.get(j));
                                SKU_DETAILS.add(skuDetailsList.get(j));
                                prices[i] = skuDetailsList.get(j).getPrice();
                                break;
                            }
                        }
                    }
                    // update the UI
                    displayAnErrorIfNeeded(BillingClient.BillingResponse.OK);
                    if (getActivity() != null) {
                        ArrayAdapter<CharSequence> adapter;
                        adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, prices);
                        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        mGoogleSpinner.setAdapter(adapter);
                        btGoogle.setEnabled(true);
                    }
                } else {
                    displayAnErrorIfNeeded(BillingClient.BillingResponse.FEATURE_NOT_SUPPORTED);
                }
            }
        }
    });
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) ArrayList(java.util.ArrayList) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with SkuDetailsResponseListener

use of com.android.billingclient.api.SkuDetailsResponseListener in project PhoneProfiles by henrichg.

the class BillingManager method querySkuDetailsAsync.

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);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams)

Aggregations

SkuDetails (com.android.billingclient.api.SkuDetails)7 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)7 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)4 ArrayList (java.util.ArrayList)3 ArrayAdapter (android.widget.ArrayAdapter)2 ReactMethod (com.facebook.react.bridge.ReactMethod)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 BillingSkuDetails (com.litekite.inappbilling.room.entity.BillingSkuDetails)1