`querySkuDetailsAsync` 返回了一个空列表,带有 BillingResult 代码 SERVICE_UNAVAILABLE。

huangapple go评论87阅读模式
英文:

querySkuDetailsAsync is returning empty list with BillingResult code SERVICE_UNAVAILABLE

问题

升级BillingClient至3.0.0版本后,大约20%的用户在查询应用内购买时出现SERVICE_UNAVAILABLE错误。skuDetailsList也为空。根据文档,SERVICE_UNAVAILABLE表示网络不可用,但是在尝试查询SKU详情后,客户端如何返回带有startConnectionOK呢?此外,我还看到一些错误,错误代码为6。我是否实现有误,还是应该向用户显示“出错了,请稍后重试”消息?在Play控制台中,我也没有看到任何国家的警告或可能导致此问题的内容。

BillingClient billingClient = BillingClient.newBuilder(getContext())
        .enablePendingPurchases()
        .setListener((billingResult, list) -> {})
        .build();

mBillingClient.startConnection(new BillingClientStateListener() {
    @Override
    public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
            createSkus(mBillingClient);
        }
    }

    @Override
    public void onBillingServiceDisconnected() {}
});

private void createSkus(BillingClient billingClient) {
    List<String> skuList = new ArrayList<>();
    skuList.add("pro");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            (billingResult, skuDetailsList) -> {
                // skuDetailsList中无内容,带有BillingResult代码2(SERVICE_UNAVAILABLE)

                BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails(skuDetailsList.get(0))
                        .build();
                billingClient.launchBillingFlow(activity, billingFlowParams);
            });
}
英文:

After upgrading the BillingClient to 3.0.0, I started getting about 20% users seeing SERVICE_UNAVAILABLE when querying for in-app purchase. The skuDetailsList is also empty. According to the docs, SERVICE_UNAVAILABLE implies network is down, but how is the client returning OK with the startConnection and sending this after trying to query the SKU details? Additionally, I'm seeing a few ERROR, which is code 6. Did I have some incorrect implementation or do I just show the user some "An error occurred. Try later" message? I also don't see any warning for any countries in the Play Console or anything that may cause this.

BillingClient billingClient = BillingClient.newBuilder(getContext())
            .enablePendingPurchases()
            .setListener((billingResult, list) -&gt; {})
            .build();

    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                createSkus(mBillingClient);
            }
        }

        @Override
        public void onBillingServiceDisconnected() {}
    });


private void createSkus(BillingClient billingClient) {
    List&lt;String&gt; skuList = new ArrayList&lt;&gt;();
    skuList.add(&quot;pro&quot;);
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            (billingResult, skuDetailsList) -&gt; {
                // skuDetailsList empty with BillingResult code 2 (SERVICE_UNAVAILABLE)

                BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                        .setSkuDetails(skuDetailsList.get(0))
                        .build();
                billingClient.launchBillingFlow(activity, billingFlowParams);
            });
}

答案1

得分: 3

我曾遇到类似的问题,其中 BillingServiceDisconnected 错误代码一直出现 - 我的问题在于我调用了两次 BillingClient.startConnection,不幸的是。

另外需要注意的是,您需要发布一个带有新更新库的 AlphaBeta 版本应用,在调试版本中测试之前,如果使用了 applicationSuffix,请将其移除。

英文:

I had a similar problem where the BillingServiceDisconnected code was coming back - my problem was I was calling BillingClient.startConnection twice, unfortunately.

Also one more thing to note you need to publish an Alpha or Beta version of your app with the newly updated library, and if you are using a applicationSuffix, remove that before you test it in a debug version.

huangapple
  • 本文由 发表于 2020年8月31日 21:47:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63672033.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定