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);
}
}
}
});
}
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);
}
Aggregations