InApp Purchase 响应正常,但未出现对话框
InApp Purchase response is OK but Dialog not appear
问题是在InApp Purchase的执行过程中,点击按钮响应正常,但是没有出现购买对话框
这是代码
//To query Google Play for in-app product details, call this method
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
Log.d(TAG, "response from query -> " + responseCode);
if (responseCode == BillingClient.BillingResponse.OK
&& skuDetailsList != null) {
for (SkuDetails skuDetails : skuDetailsList) {
String sku = skuDetails.getSku();
String price = skuDetails.getPrice();
if ("minimum".equals(sku)) {
//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.
mOneDollarPurchasePrice = price;
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build();
responseCode = mBillingClient.launchBillingFlow(ShopActivity.this, flowParams);
} else {
//TODO Handle other scenarios of SKU
}
}
购买后必须使用商品
private void consumeFromLibrary() {
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(@BillingClient.BillingResponse int responseCode, String outToken) {
Log.d(TAG, "Consume response -> " + responseCode);
if (responseCode == BillingClient.BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
} else if (responseCode == BillingClient.BillingResponse.SERVICE_DISCONNECTED) {
Log.d(TAG, "SERVICE DISCONNECTED");
}
}
};
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
List<Purchase> purchaseList = purchasesResult.getPurchasesList();
for (Purchase purchase : purchaseList) {
mBillingClient.consumeAsync(purchase.getPurchaseToken(), listener);
}
}
问题是在InApp Purchase的执行过程中,点击按钮响应正常,但是没有出现购买对话框 这是代码
//To query Google Play for in-app product details, call this method
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
Log.d(TAG, "response from query -> " + responseCode);
if (responseCode == BillingClient.BillingResponse.OK
&& skuDetailsList != null) {
for (SkuDetails skuDetails : skuDetailsList) {
String sku = skuDetails.getSku();
String price = skuDetails.getPrice();
if ("minimum".equals(sku)) {
//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.
mOneDollarPurchasePrice = price;
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build();
responseCode = mBillingClient.launchBillingFlow(ShopActivity.this, flowParams);
} else {
//TODO Handle other scenarios of SKU
}
}
购买后必须使用商品
private void consumeFromLibrary() {
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(@BillingClient.BillingResponse int responseCode, String outToken) {
Log.d(TAG, "Consume response -> " + responseCode);
if (responseCode == BillingClient.BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
} else if (responseCode == BillingClient.BillingResponse.SERVICE_DISCONNECTED) {
Log.d(TAG, "SERVICE DISCONNECTED");
}
}
};
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
List<Purchase> purchaseList = purchasesResult.getPurchasesList();
for (Purchase purchase : purchaseList) {
mBillingClient.consumeAsync(purchase.getPurchaseToken(), listener);
}
}