use of com.android.billingclient.api.BillingClient in project sms-backup-plus by jberkel.
the class DonationActivity method checkUserDonationStatus.
public static void checkUserDonationStatus(Context context, final DonationStatusListener listener) {
final BillingClient helper = BillingClient.newBuilder(context).enablePendingPurchases().setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) {
log("onPurchasesUpdated(" + result + ", " + purchases + ")");
}
}).build();
helper.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult result) {
log("checkUserHasDonated: onBillingSetupFinished(" + result + ")");
try {
if (result.getResponseCode() == OK) {
PurchasesResult purchasesResult = helper.queryPurchases(INAPP);
if (result.getResponseCode() == OK) {
listener.userDonationState(userHasDonated(purchasesResult.getPurchasesList()) ? DONATED : NOT_DONATED);
} else {
listener.userDonationState(UNKNOWN);
}
} else {
listener.userDonationState(result.getResponseCode() == BILLING_UNAVAILABLE ? NOT_AVAILABLE : UNKNOWN);
}
} finally {
try {
helper.endConnection();
} catch (Exception ignored) {
}
}
}
public void onBillingServiceDisconnected() {
}
});
}
use of com.android.billingclient.api.BillingClient in project scroball by peterjosling.
the class MainActivity method onResume.
@Override
protected void onResume() {
super.onResume();
billingClient = new BillingClient.Builder(this).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
if (billingResponseCode == BillingResponse.OK) {
Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
onPurchasesUpdated(purchasesResult.getResponseCode(), purchasesResult.getPurchasesList());
}
}
@Override
public void onBillingServiceDisconnected() {
}
});
}
Aggregations