首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓3到5- PurchasesResult,queryPurchases,getPurchasesList,getSku

安卓3到5- PurchasesResult,queryPurchases,getPurchasesList,getSku
EN

Stack Overflow用户
提问于 2022-05-18 12:25:50
回答 1查看 425关注 0票数 3

我想使用android计费版本5,问题是我使用的是第3版,有些东西现在被废弃了。

我有过这个,但是PurchasesResult,queryPurchases和getPurchasesList已经不存在了:

代码语言:javascript
复制
@Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if(billingResult.getResponseCode()==BillingClient.BillingResponseCode.OK){
                    Purchase.PurchasesResult queryPurchase = billingClient.queryPurchases(INAPP);
                    List<Purchase> queryPurchases = queryPurchase.getPurchasesList();
                    if(queryPurchases!=null && queryPurchases.size()>0){
                        handlePurchases(queryPurchases);
                    }

我如何使它在第5版上工作呢?

也无法解析getSku():

代码语言:javascript
复制
//if purchase is pending
            else if( PRODUCT_ID.equals(purchase.getSku()) && purchase.getPurchaseState() == Purchase.PurchaseState.PENDING)
            {
                Toast.makeText(getApplicationContext(),
                        R.string.plus_pending, Toast.LENGTH_SHORT).show();
            }

谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-11-11 13:58:19

他是Google计费库4到5迁移指南https://developer.android.com/google/play/billing/migrate-gpblv5#processing-purchases

从您的例子来看,我认为您必须调用billingClient.queryPurchasesAsync。而且您不需要再调用queryPurchase.getPurchasesList(),您将收到列表购买作为侦听器参数返回。

代码语言:javascript
复制
billingClient.queryPurchasesAsync(
QueryPurchasesParams.newBuilder().setProductType(ProductType.SUBS).build(),
new PurchasesResponseListener() {
    public void onQueryPurchasesResponse(
            @NonNull BillingResult billingResult,
            @NonNull List<Purchase> purchases) {
        // Process the result
        if(purchases.size()>0){
            handlePurchases(purchases);
        }
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72289150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档