本文整理汇总了Java中com.android.billingclient.api.Purchase类的典型用法代码示例。如果您正苦于以下问题:Java Purchase类的具体用法?Java Purchase怎么用?Java Purchase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Purchase类属于com.android.billingclient.api包,在下文中一共展示了Purchase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
for (Purchase purchase : purchases) {
handlePurchase(purchase);
}
listener.onPurchasesUpdated(purchases);
} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
// Handle an error caused by a user canceling the purchase flow.
Log.i(TAG, "User canceled.");
} else {
// Handle any other error codes.
Log.i(TAG, "Unknown error. Response code: " + responseCode);
}
}
示例2: onResume
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@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() {}
});
}
示例3: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(int responseCode, List<Purchase> purchases) {
if (responseCode != BillingResponse.OK) {
purchaseFailed();
} else if (purchases != null) {
for (Purchase purchase : purchases) {
if (purchase.getSku().equals(REMOVE_ADS_SKU)) {
RelativeLayout parent = (RelativeLayout) adView.getParent();
if (parent != null) {
parent.removeView(adView);
}
this.invalidateOptionsMenu();
this.adsRemoved = true;
SharedPreferences.Editor editor = application.getSharedPreferences().edit();
editor.putBoolean(REMOVE_ADS_SKU, true);
editor.apply();
}
}
}
}
示例4: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(List<Purchase> purchases) {
if (!billingManager.shouldDisplayAds()) {
removeAds();
drawerView.getMenu().findItem(R.id.remove_ads).setVisible(false);
}
}
示例5: queryPurchases
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
private void queryPurchases() {
final Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
final List<Purchase> purchases = result.getPurchasesList();
if (purchases != null) {
for (Purchase purchase : purchases) {
handlePurchase(purchase);
}
}
}
示例6: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* After google payment successfully get response
* @param purchaseList successful payment receive response
*/
@Override
public void onPurchasesUpdated(List<Purchase> purchaseList) {
for (Purchase purchase : purchaseList) {
if (Objects.equals(purchase.getSku(), SKU_ID)) {
mActivity.onPurchasesUpdated(purchaseList);
break;
}
}
}
示例7: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* After google payment successfully get response
* @param purchaseList successful payment receive response
*/
void onPurchasesUpdated(List<Purchase> purchaseList) {
Intent resultIntent = new Intent();
Bundle args = new Bundle();
args.putSerializable("result", (Serializable) purchaseList);
resultIntent.putExtra("PurchaseBundle", args);
activity.setResult(Activity.RESULT_OK, resultIntent);
activity.finish();
}
示例8: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* Handle a callback that purchases were updated from the Billing library
*/
@Override
public void onPurchasesUpdated(int resultCode, List<Purchase> purchases) {
if (resultCode == BillingResponse.OK) {
for (Purchase purchase : purchases) {
handlePurchase(purchase);
}
mBillingUpdatesListener.onPurchasesUpdated(mPurchases);
} else if (resultCode == BillingResponse.USER_CANCELED) {
Log.i(TAG, "onPurchasesUpdated() - user cancelled the purchase flow - skipping");
} else {
Log.w(TAG, "onPurchasesUpdated() got unknown resultCode: " + resultCode);
}
}
示例9: handlePurchase
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* Handles the purchase
* <p>Note: Notice that for each purchase, we check if signature is valid on the client.
* It's recommended to move this check into your backend.
* See {@link Security#verifyPurchase(String, String, String)}
* </p>
* @param purchase Purchase to be handled
*/
private void handlePurchase(Purchase purchase) {
if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
Log.i(TAG, "Got a purchase: " + purchase + "; but signature is bad. Skipping...");
return;
}
Log.d(TAG, "Got a verified purchase: " + purchase);
mPurchases.add(purchase);
}
示例10: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* Handle a callback that purchases were updated from the Billing library
*/
@Override
public void onPurchasesUpdated(int resultCode, List<Purchase> purchases) {
if (resultCode == BillingResponse.OK) {
for (Purchase purchase : purchases) {
handlePurchase(purchase);
}
billingUpdatesListener.onPurchasesUpdated(this.purchases);
} else if (resultCode == BillingResponse.USER_CANCELED) {
Log.i(TAG, "onPurchasesUpdated() - user cancelled the purchase flow - skipping");
} else {
Log.w(TAG, "onPurchasesUpdated() got unknown resultCode: " + resultCode);
}
}
示例11: handlePurchase
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
/**
* Handles the purchase
* <p>Note: Notice that for each purchase, we check if signature is valid on the client.
* It's recommended to move this check into your backend.
* See {@link Security#verifyPurchase(String, String, String)}
* </p>
*
* @param purchase Purchase to be handled
*/
private void handlePurchase(Purchase purchase) {
if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
Log.i(TAG, "Got a purchase: " + purchase + "; but signature is bad. Skipping...");
return;
}
Log.d(TAG, "Got a verified purchase: " + purchase);
purchases.add(purchase);
}
示例12: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(@BillingClient.BillingResponse int responseCode, List<Purchase> purchases) {
if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
if(getView() != null) {
// Apply preference
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("donationPurchased", true);
editor.apply();
// Destroy Ad
AdView mAdView = getActivity().findViewById(R.id.adView);
mAdView.setVisibility(GONE);
mAdView.destroy();
showDonatorStatus();
}
} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
// Handle an error caused by a user cancelling the purchase flow.
if(getView() != null) {
Snackbar.make(getView(), R.string.donation_cancelled, Snackbar.LENGTH_SHORT).show();
}
} else {
// Handle any other error codes.
if(getView() != null) {
Snackbar.make(getView(), R.string.donation_cancelled, Snackbar.LENGTH_SHORT).show();
}
}
}
示例13: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(@BillingClient.BillingResponse int responseCode, List<Purchase> purchases) {
//if (responseCode == BillingClient.BillingResponse.OK && purchases != null) {
// Success
//} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
// Handle an error caused by a user cancelling the purchase flow.
//} else {
// Handle any other error codes.
//}
}
示例14: onPurchasesUpdated
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onPurchasesUpdated(List<Purchase> purchaseList) {
mGoldMonthly = false;
mGoldYearly = false;
for (Purchase purchase : purchaseList) {
switch (purchase.getSku()) {
case PremiumDelegate.SKU_ID:
Log.d(TAG, "You are Premium! Congratulations!!!");
mIsPremium = true;
break;
case GasDelegate.SKU_ID:
Log.d(TAG, "We have gas. Consuming it.");
// We should consume the purchase and fill up the tank once it was consumed
mActivity.getBillingManager().consumeAsync(purchase.getPurchaseToken());
break;
case GoldMonthlyDelegate.SKU_ID:
mGoldMonthly = true;
break;
case GoldYearlyDelegate.SKU_ID:
mGoldYearly = true;
break;
}
}
mActivity.showRefreshedUi();
}
示例15: onQueryInventoryFinished
import com.android.billingclient.api.Purchase; //导入依赖的package包/类
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
isPro = (inv.hasPurchase(SKU_UPGRADE) &&
inv.getPurchase(SKU_UPGRADE).getPurchaseState() == Purchase.PurchaseState.PURCHASED);
}