英文:
querySkuDetailsAsync is returning empty list with BillingResult code SERVICE_UNAVAILABLE
问题
升级BillingClient至3.0.0版本后,大约20%的用户在查询应用内购买时出现SERVICE_UNAVAILABLE
错误。skuDetailsList也为空。根据文档,SERVICE_UNAVAILABLE
表示网络不可用,但是在尝试查询SKU详情后,客户端如何返回带有startConnection
的OK
呢?此外,我还看到一些错误,错误代码为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) -> {})
.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 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
,不幸的是。
另外需要注意的是,您需要发布一个带有新更新库的 Alpha
或 Beta
版本应用,在调试版本中测试之前,如果使用了 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论