use of com.android.billingclient.api.Purchase.PurchasesResult in project Android-InAppBilling by LiteKite.
the class BillingManager method queryPurchasesLocally.
/**
* Query purchases across various use cases and deliver the result in a formalized way through
* a listener
*/
private void queryPurchasesLocally() {
Runnable queryToExecute = new Runnable() {
@Override
public void run() {
PurchasesResult purchasesResult = myBillingClient.queryPurchases(SkuType.INAPP);
// If there are subscriptions supported, we add subscription rows as well
if (areSubscriptionsSupported()) {
PurchasesResult subscriptionResult = myBillingClient.queryPurchases(SkuType.SUBS);
BaseActivity.printLog(TAG, "Querying subscriptions result code: " + subscriptionResult.getResponseCode() + " res: " + subscriptionResult.getPurchasesList().size());
if (subscriptionResult.getResponseCode() == BillingResponse.OK) {
purchasesResult.getPurchasesList().addAll(subscriptionResult.getPurchasesList());
} else {
BaseActivity.printLog(TAG, "Got an error response " + "trying to query subscription purchases");
}
} else if (purchasesResult.getResponseCode() == BillingResponse.OK) {
BaseActivity.printLog(TAG, "Skipped subscription purchases query " + "since they are not supported");
} else {
BaseActivity.printLog(TAG, "queryPurchases() got an error response code: " + purchasesResult.getResponseCode());
}
BaseActivity.printLog(TAG, "Local Query Purchase List Size: " + purchasesResult.getPurchasesList().size());
storePurchaseResultsLocally(purchasesResult.getPurchasesList());
}
};
executeServiceRequest(queryToExecute);
}
use of com.android.billingclient.api.Purchase.PurchasesResult 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.Purchase.PurchasesResult in project Osmand by osmandapp.
the class BillingManager method queryPurchases.
/**
* Query purchases across various use cases and deliver the result in a formalized way through
* a listener
*/
public void queryPurchases() {
Runnable queryToExecute = new Runnable() {
@Override
public void run() {
long time = System.currentTimeMillis();
PurchasesResult purchasesResult = mBillingClient.queryPurchases(SkuType.INAPP);
LOG.info("Querying purchases elapsed time: " + (System.currentTimeMillis() - time) + "ms");
// If there are subscriptions supported, we add subscription rows as well
if (areSubscriptionsSupported()) {
PurchasesResult subscriptionResult = mBillingClient.queryPurchases(SkuType.SUBS);
LOG.info("Querying purchases and subscriptions elapsed time: " + (System.currentTimeMillis() - time) + "ms");
LOG.info("Querying subscriptions result code: " + subscriptionResult.getResponseCode() + " res: " + subscriptionResult.getPurchasesList().size());
if (subscriptionResult.getResponseCode() == BillingResponseCode.OK) {
purchasesResult.getPurchasesList().addAll(subscriptionResult.getPurchasesList());
} else {
LOG.error("Got an error response trying to query subscription purchases");
}
} else if (purchasesResult.getResponseCode() == BillingResponseCode.OK) {
LOG.info("Skipped subscription purchases query since they are not supported");
} else {
LOG.warn("queryPurchases() got an error response code: " + purchasesResult.getResponseCode());
}
onQueryPurchasesFinished(purchasesResult);
}
};
executeServiceRequest(queryToExecute);
}
Aggregations