gpt4 book ai didi

Android BillingClient 错误 : "Exception while launching billing flow: ; for sku: android.test.purchased; try to reconnect"

转载 作者:行者123 更新时间:2023-12-03 21:19:30 24 4
gpt4 key购买 nike

我一直在尝试使用应用内支付构建一个 android 应用程序,但在设置时遇到了麻烦。我正在调用以下内容:

      Activity activity = new Activity();
billingClient = BillingClient.newBuilder(this).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
if (billingResponseCode == BillingResponse.OK) {
List<String> skuList = new ArrayList<> ();
skuList.add("android.test.purchased");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(SkuType.INAPP);
billingClient.querySkuDetailsAsync(params.build(),
(responseCode, skuDetailsList) -> {
if (responseCode == BillingResponse.OK
&& skuDetailsList != null) {
for (SkuDetails skuDetails : skuDetailsList) {
System.out.println("The price is "+skuDetails.getPrice());
BillingFlowParams flowParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
int code = billingClient.launchBillingFlow(activity,flowParams);
System.out.println("Code is: "+code);
}
}
});
}
}
@Override
public void onBillingServiceDisconnected() {
System.out.print("Billing disconnected?");
}
});

当我运行它时,我得到代码是-1,我得到错误: Exception while launching billing flow: ; for sku: android.test.purchased; try to reconnect我发现错误代码 -1 是“Play Store service is not connected now - 可能是 transient ”( https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse)。我已经尝试了测试产品 ID ( android.test.purchased ),以及我创建的真实产品 ID,结果相同。我还重新启动了(物理)设备。我可以像往常一样访问 Play 商店应用程序,所以我不知道我在这里做错了什么。

最佳答案

我得到了同样的错误:
W/BillingClient(25145): Exception while launching billing flow: ; for sku: someSKU; try to reconnect
我的代码几乎完全基于 Google 官方的示例“TrivialDrive_v2”,使用计费库版本 1.2.2。我的主要 Activity 扩展了 NativeActivity。 This没有帮助。在寻找可能的原因一天后,我没有想法了😥

看着logcat,我偶然发现了这条消息
I/ActivityManager(962): START u0 {cmp=com.mypackage.myapp/com.android.billingclient.api.ProxyBillingActivity (has extras)} from uid 10116 on display 0
这条消息没有任何问题,它只是一个信息,但它是错误发生之前的最后一条消息。于是我搜索了“ProxyBillingActivity”,发现 this .出于好奇,我添加了以下定义

<activity
android:name="com.android.billingclient.api.ProxyBillingActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

到我的 list 文件,瞧!计费工作。然后我搜索了整个“TrivialDrive_v2”示例源和所有 xml 和 list 文件,看看它们是否也有这样的定义,但它们没有。那好吧。

关于Android BillingClient 错误 : "Exception while launching billing flow: ; for sku: android.test.purchased; try to reconnect",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55769812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com