Android Google 计费客户端 - onSkuDetailsResponse 列表始终为空
Android Google Billing Client - onSkuDetailsResponse Always Empty List
我想知道你能帮忙吗。我按照 https://developer.android.com/google/play/billing/integrate 上的说明进行操作,但我似乎无法让购买流程正常运行。账单似乎设置正常,但当我尝试查询我的应用内商品时,列表总是 return 为空。有人可以帮忙吗?
在我的应用级别 build.gradle 文件中,我包含了 Google 计费 SDK:
implementation 'com.android.billingclient:billing:3.0.0'
然后我创建了一个 activity 来测试代码。它首先初始化 BillingClient 并启动连接。连接似乎正确地完成了设置。设置正确后,我会尝试在 'Store presence' > 'In-app products' > 'Manage products'
下的 Google Play Console 中查询可用的产品
下面是 Activity 中应该启动进程和 return SkuDetails 列表的代码,但不幸的是 return 返回时是空的。
private BillingClient billingClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_billing);
this.billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this.purchaseUpdateListener)
.build();
this.billingClient.startConnection(billingClientStateListener);
}
private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
Log.d("Billing", "onPurchasesUpdated - List Size: " + list.size());
}
};
private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.d("Billing", "onBillingSetupFinished - OK");
queryProducts();
} else {
Log.d("Billing", "onBillingSetupFinished - Something wrong response Code: " + billingResult.getResponseCode());
}
}
@Override
public void onBillingServiceDisconnected() {
Log.d("Billing", "Service disconnected");
}
};
private void queryProducts() {
List<String> productIdsList = new ArrayList<>();
productIdsList.add("test.billing.001");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(productIdsList).setType(BillingClient.SkuType.INAPP);
this.billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List< SkuDetails > list) {
Log.d("Billing", "onSkuDetailsResponse - List Size: " + list.size());
}
});
}
因此对于遇到类似问题的任何人来说,似乎(无论如何对我而言)我的应用程序需要成功发布才能从应用程序中检索应用程序内产品。我的应用发布后,我就可以查询和使用应用内商品了。
我想知道你能帮忙吗。我按照 https://developer.android.com/google/play/billing/integrate 上的说明进行操作,但我似乎无法让购买流程正常运行。账单似乎设置正常,但当我尝试查询我的应用内商品时,列表总是 return 为空。有人可以帮忙吗?
在我的应用级别 build.gradle 文件中,我包含了 Google 计费 SDK:
implementation 'com.android.billingclient:billing:3.0.0'
然后我创建了一个 activity 来测试代码。它首先初始化 BillingClient 并启动连接。连接似乎正确地完成了设置。设置正确后,我会尝试在 'Store presence' > 'In-app products' > 'Manage products'
下的 Google Play Console 中查询可用的产品下面是 Activity 中应该启动进程和 return SkuDetails 列表的代码,但不幸的是 return 返回时是空的。
private BillingClient billingClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_billing);
this.billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this.purchaseUpdateListener)
.build();
this.billingClient.startConnection(billingClientStateListener);
}
private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
Log.d("Billing", "onPurchasesUpdated - List Size: " + list.size());
}
};
private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.d("Billing", "onBillingSetupFinished - OK");
queryProducts();
} else {
Log.d("Billing", "onBillingSetupFinished - Something wrong response Code: " + billingResult.getResponseCode());
}
}
@Override
public void onBillingServiceDisconnected() {
Log.d("Billing", "Service disconnected");
}
};
private void queryProducts() {
List<String> productIdsList = new ArrayList<>();
productIdsList.add("test.billing.001");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(productIdsList).setType(BillingClient.SkuType.INAPP);
this.billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List< SkuDetails > list) {
Log.d("Billing", "onSkuDetailsResponse - List Size: " + list.size());
}
});
}
因此对于遇到类似问题的任何人来说,似乎(无论如何对我而言)我的应用程序需要成功发布才能从应用程序中检索应用程序内产品。我的应用发布后,我就可以查询和使用应用内商品了。