android - 用户申请订阅 InAppPurchases 时是否有回调?
问题描述
我已经按照官方指南实现了订阅流程。但是,当用户在 Google Api 一侧确认订阅信息时,是否可以获得订阅信息?因为在这里它是无效的,没有任何回报。我如何才能访问该交易?
private void startConnection(String type) {
//Call newBuilder() to create an instance of BillingClient You must also call setListener()
//passing a reference to a PurchasesUpdatedListener to receive updates on purchases initiated
// by your app, as well as those initiated by the Google Play Store.
BillingClient billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build();
billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS_UPDATE);
//Establish a connection to Google Play. The setup process is asynchronous, and you must
//implement a BillingClientStateListener to receive a callback once the setup of the client
//is complete and it’s ready to make further requests.
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
String s = billingResult.getDebugMessage();
String ss = String.valueOf(billingResult.getResponseCode());
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
//specifies a list of product ID strings and a SkuType
List<String> skuList = new ArrayList<>();
skuList.add(type);
// skuList.add("vip");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
//IMPORTANT The SkuType can be either SkuType.INAPP for one-time products or SkuType.SUBS for subscriptions
params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
billingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult billingResult,
List<SkuDetails> skuDetailsList) {
// Process the result.
//Retrieving a product’s price is an important step before a user can purchase a product because
// the price is different for each user based on their country of origin.
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
for (SkuDetails skuDetails : skuDetailsList) {
String sku = skuDetails.getSku();
String price = skuDetails.getPrice();
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(0))
.build();
billingClient.launchBillingFlow(RewardVideoActivity.this, flowParams);
}
}
}
});
}
}
@Override
public void onBillingServiceDisconnected() {
String s = "error";
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
}
解决方案
回调结果来自接口PurchasesUpdatedListener
实现
onPurchasesUpdated(BillingResult billingResult, List<Purchase> list)
推荐阅读
- xamarin - 如何在 C# 后端的模板中更改标签的颜色?
- r - ggarrange 绘制列表中的所有地块
- mongodb - 使用 Mongo DB (Mongoose) 中的值预填充 Mustache.JS 模板
- google-cloud-platform - 如何使用 API 或 Terraform 模板在 GCP 中创建 StackDriver 工作区
- java - List WebElement 总是从下拉列表中选择第一个元素,但我想选择第四个元素
- blockchain - 查看以太坊智能合约的源代码
- python - python 2.7 中的等效 urllib.parse.unquote()
- azure-active-directory - New-AzureRmADGroup 没有办法指示组是否启用了安全性?
- javascript - 为什么我的 setTimeout 函数会运行两次?
- sql-server - SQL Server 2016 Express 中的行级安全性?