Android Google Billing 客户端 - onSkuDetailsResponse 始终返回空列表
创始人
2024-08-13 23:00:13
0

在Android Google Billing客户端中,当onSkuDetailsResponse方法始终返回空列表时,可能有几种原因。以下是一些可能的解决方法和代码示例:

  1. 检查Google Play Console设置:确保已正确设置了商品和订阅项目,并且它们处于活动状态。

  2. 检查测试账号和许可证:确保您使用的测试账号是正确的,并且已添加相应的许可证。

  3. 检查Google Play服务和Billing库版本:确保您的应用程序使用了最新版本的Google Play服务和Billing库。您可以通过在项目级别的build.gradle文件中的dependencies部分添加以下依赖项来引入最新版本:

dependencies {
    implementation 'com.android.billingclient:billing:4.0.0'
    implementation 'com.google.android.gms:play-services-auth:19.2.0'
}
  1. 确保正确实现了PurchasesUpdatedListener接口:在您的ActivityFragment中,确保您正确实现了PurchasesUpdatedListener接口,并在onPurchasesUpdated方法中处理购买更新逻辑。
public class MainActivity extends AppCompatActivity implements PurchasesUpdatedListener {
    private BillingClient billingClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化BillingClient
        billingClient = BillingClient.newBuilder(this)
                .setListener(this)
                .enablePendingPurchases()
                .build();

        // 连接到Google Play服务
        billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    // 查询商品详情
                    List skuList = new ArrayList<>();
                    skuList.add("your_product_id");
                    SkuDetailsParams params = SkuDetailsParams.newBuilder()
                            .setSkusList(skuList)
                            .setType(BillingClient.SkuType.INAPP)
                            .build();
                    billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(BillingResult billingResult, List skuDetailsList) {
                            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
                                // 处理返回的商品详情列表
                                for (SkuDetails skuDetails : skuDetailsList) {
                                    // ...
                                }
                            } else {
                                Log.e("Billing", "Failed to retrieve SKU details: " + billingResult.getDebugMessage());
                            }
                        }
                    });
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                // 处理断开连接的逻辑
            }
        });
    }

    @Override
    public void onPurchasesUpdated(BillingResult billingResult, List purchases) {
        // 处理购买更新逻辑
    }
}

请确保在上面的代码示例中,您替换了your_product_id为您在Google Play Console上创建的产品ID。此外,还应当处理错误情况和断开连接的情况,以提高应用程序的健壮性。

如果以上解决方法仍然无法解决问题,请确保您的Google Play Console设置和许可证配置正确,并且您的商品和订阅项目处于活动状态。您还可以根据您的具体情况查看Google Play Billing文档和调试日志,以获取更多帮助和指导。

相关内容

热门资讯

透视推荐!wepoker透视是... 透视推荐!wepoker透视是真的吗(透视)wepoker私人定制透视,教程项目(了解有挂)-哔哩哔...
hhpoker为什么一直输!w... hhpoker为什么一直输!wepoker辅助真的假的(透视)攻略-真是分享真的有挂1、许多玩家不知...
透视必备!wepoker私人局... 透视必备!wepoker私人局规律(透视)aapoker怎么设置抽水,教程指南书(有挂解惑)-哔哩哔...
德州辅助工具到底怎么样!wep... 德州辅助工具到底怎么样!wepoker开脚本视频(透视)器-都是推荐是有挂1、玩家可以在德州辅助工具...
透视分享!wpk透视辅助下载(... 透视分享!wpk透视辅助下载(透视)hhpoker真能买到挂吗,教程操作(真的有挂)-哔哩哔哩1、不...
aa poker辅助包!德州透... aa poker辅助包!德州透视脚本(透视)工具-本来揭幕存在有挂1、该软件可以轻松地帮助玩家将德州...
透视详细!cloudpoker... 透视详细!cloudpoker怎么开挂(透视)哈糖大菠萝能开挂吗,教程阶段(揭秘有挂)-哔哩哔哩1、...
wepoker透视苹果系统!w... wepoker透视苹果系统!wepoker免费脚本咨询(透视)方法-原来教你是有挂1)wepoker...
透视科普!xpoker辅助工具... 透视科普!xpoker辅助工具(透视)wejoker辅助软件价格,教程窍要(有挂秘笈)-哔哩哔哩1、...
pokernow辅助工具!aa... pokernow辅助工具!aapoker辅助插件工具(透视)技巧-好像透视是真的挂1.aapoker...