use of com.android.billingclient.api.SkuDetails 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.SkuDetails in project PhoneProfiles by henrichg.
the class DonationFragment method purchaseUnsuccessful.
public void purchaseUnsuccessful(List<Purchase> purchases) {
if (purchases != null) {
for (Purchase purchase : purchases) {
String sku = purchase.getSku();
for (SkuDetails skuDetail : SKU_DETAILS) {
if (skuDetail.getSku().equals(sku)) {
PPApplication.logE(TAG, "purchaseUnsuccessful - sku=" + sku);
PPApplication.logE(TAG, "purchaseUnsuccessful - currency=" + skuDetail.getPriceCurrencyCode());
PPApplication.logE(TAG, "purchaseUnsuccessful - priceS=" + skuDetail.getPrice());
PPApplication.logE(TAG, "purchaseUnsuccessful - priceMicros=" + skuDetail.getPriceAmountMicros());
PPApplication.logE(TAG, "purchaseUnsuccessful - price=" + skuDetail.getPriceAmountMicros() / 1000000.0);
Answers.getInstance().logPurchase(new PurchaseEvent().putItemPrice(BigDecimal.valueOf(skuDetail.getPriceAmountMicros() / 1000000.0)).putCurrency(Currency.getInstance(skuDetail.getPriceCurrencyCode())).putItemName("Donation").putItemId(sku).putSuccess(false));
}
}
}
}
}
use of com.android.billingclient.api.SkuDetails 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);
}
use of com.android.billingclient.api.SkuDetails in project Android-InAppBilling by LiteKite.
the class BillingManager method storeSkuDetailsLocally.
/**
* Stores SKU Details on local storage.
*
* @param skuDetailsList list of SKU Details returned from the queries.
*/
private void storeSkuDetailsLocally(List<SkuDetails> skuDetailsList) {
final List<BillingSkuDetails> billingSkuDetailsList = new ArrayList<>();
for (SkuDetails skuDetails : skuDetailsList) {
BillingSkuDetails billingSkuDetails = new BillingSkuDetails();
billingSkuDetails.skuID = skuDetails.getSku();
billingSkuDetails.skuType = skuDetails.getType();
billingSkuDetails.skuPrice = skuDetails.getPrice();
billingSkuDetailsList.add(billingSkuDetails);
}
new Thread(new Runnable() {
@Override
public void run() {
AppDatabase.getAppDatabase(context).getBillingDao().insertSkuDetails(billingSkuDetailsList);
}
}).start();
}
Aggregations