Android 计费;如何解决 "The item you were attempting to purchase could not be found"
Android Billing; how to resolve "The item you were attempting to purchase could not be found"
由于最近对 Google 计费库和开发人员控制台进行了所有更改,因此很难应用 2014 年的答案,因此我再次发帖讨论这个主题,希望能找到一个现代的答案。
我正在使用 Google 计费库 2.2.0
问题:
我已经设置了许可证:
我还设置了许可证测试:
我还向内部测试轨道发布了一个发布版本(使用发布证书签名):
相关代码示例:
private final String SKU_TEST_PROD_1YR = "test_prod_id_1_year";
private final String SKU_TEST_PROD_6MN = "test_prod_id_6_month";
private final String SKU_TEST_PROD_1MN = "test_prod_id_1_month";
private BillingClient billingClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> iapProdIdList = Arrays.asList(SKU_TEST_PROD_1YR, SKU_TEST_PROD_6MN, SKU_TEST_PROD_1MN);
setupBillingClient(this, iapProdIdList);
}
@Override
protected void onDestroy() {
super.onDestroy();
billingClient.endConnection();
}
private void setupBillingClient(Context context, List<String> iapProdList) {
billingClient = BillingClient.newBuilder(context).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
loadAllSubscriptionProductIdDetails(iapProdList);
}
}
@Override
public void onBillingServiceDisconnected() { }
});
}
private void loadAllSubscriptionProductIdDetails(List<String> iapProdList) {
if (billingClient.isReady()) {
SkuDetailsParams params = SkuDetailsParams.newBuilder().setSkusList(iapProdList).setType(BillingClient.SkuType.SUBS).build();
billingClient.querySkuDetailsAsync(params, (billingResult, prodDetailList) -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !prodDetailList.isEmpty()) {
for (SkuDetails prodDetail : prodDetailList) {
String productSku = prodDetail.getSku();
switch(productSku) {
case SKU_TEST_PROD_1YR : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1Yr.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_6MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap6mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_1MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
default :
Toast.makeText(this, "Did not find Product in-app: "+ productSku, Toast.LENGTH_SHORT).show();
}
}//end of FOR
}//end of IF
});
} else {
Toast.makeText(this, "billingClient is NOT ready", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {
if (billingResult != null && list != null) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (Purchase purchase : list) {
if(!purchase.isAcknowledged()) acknowledgePurchase(purchase.getPurchaseToken());
}
}
else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
Toast.makeText(this, "User Canceled", Toast.LENGTH_SHORT).show();
}
else if(billingResult.getResponseCode()== BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
Toast.makeText(this, "Already Purchased", Toast.LENGTH_SHORT).show();
}
}
}
private void acknowledgePurchase(String purchaseToken) {
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build();
billingClient.acknowledgePurchase(params, billingResult -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Toast.makeText(this, "Purchase Acknowledged", Toast.LENGTH_SHORT).show();
}
});
}
当我点击我的任何 [购买订阅] 按钮时,billingClient.launchBillingFlow(this, billingFlowParams);
被正确触发并且 SKU 是正确的。
据我所知,所有开发控制台都已正确设置。
我想向我的经理演示 IAP,但是,"The item you were attempting to purchase could not be found" 限制了我的风格!
我做错了什么?
我认为您的 loadAllSubscriptionProductIdDetails()
方法设计有误。
您只需在用户点击时调用 querySkuDetailsAsync()
,在 setSkusList()
参数中使用单个项目,即要购买的项目,然后:
@Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList.size() > 0) {
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(0))
.build();
billingClient.launchBillingFlow(activity, flowParams);
}
}
我在问题中发布的代码功能齐全。由于开发者控制台配置问题是 100% :
修复:
1) 将应用提升为 Alpha 版 最低(内部测试轨道不起作用!)
2) 单击 Alpha 轨道上的 [管理],然后通过电子邮件将选择加入 link 发送给您的测试人员
3) 您的测试人员会说 "when I click this link, the Play Store says the app isn't found"。告诉他们放松 30 分钟 - Google 控制台需要 30 分钟来处理这种复杂性。
让他们下载早期发布版本,IAP 突然就可以使用了!
由于最近对 Google 计费库和开发人员控制台进行了所有更改,因此很难应用 2014 年的答案,因此我再次发帖讨论这个主题,希望能找到一个现代的答案。
我正在使用 Google 计费库 2.2.0
问题:
我已经设置了许可证:
我还设置了许可证测试:
我还向内部测试轨道发布了一个发布版本(使用发布证书签名):
相关代码示例:
private final String SKU_TEST_PROD_1YR = "test_prod_id_1_year";
private final String SKU_TEST_PROD_6MN = "test_prod_id_6_month";
private final String SKU_TEST_PROD_1MN = "test_prod_id_1_month";
private BillingClient billingClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> iapProdIdList = Arrays.asList(SKU_TEST_PROD_1YR, SKU_TEST_PROD_6MN, SKU_TEST_PROD_1MN);
setupBillingClient(this, iapProdIdList);
}
@Override
protected void onDestroy() {
super.onDestroy();
billingClient.endConnection();
}
private void setupBillingClient(Context context, List<String> iapProdList) {
billingClient = BillingClient.newBuilder(context).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
loadAllSubscriptionProductIdDetails(iapProdList);
}
}
@Override
public void onBillingServiceDisconnected() { }
});
}
private void loadAllSubscriptionProductIdDetails(List<String> iapProdList) {
if (billingClient.isReady()) {
SkuDetailsParams params = SkuDetailsParams.newBuilder().setSkusList(iapProdList).setType(BillingClient.SkuType.SUBS).build();
billingClient.querySkuDetailsAsync(params, (billingResult, prodDetailList) -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !prodDetailList.isEmpty()) {
for (SkuDetails prodDetail : prodDetailList) {
String productSku = prodDetail.getSku();
switch(productSku) {
case SKU_TEST_PROD_1YR : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1Yr.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_6MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap6mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_1MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
default :
Toast.makeText(this, "Did not find Product in-app: "+ productSku, Toast.LENGTH_SHORT).show();
}
}//end of FOR
}//end of IF
});
} else {
Toast.makeText(this, "billingClient is NOT ready", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {
if (billingResult != null && list != null) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (Purchase purchase : list) {
if(!purchase.isAcknowledged()) acknowledgePurchase(purchase.getPurchaseToken());
}
}
else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
Toast.makeText(this, "User Canceled", Toast.LENGTH_SHORT).show();
}
else if(billingResult.getResponseCode()== BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
Toast.makeText(this, "Already Purchased", Toast.LENGTH_SHORT).show();
}
}
}
private void acknowledgePurchase(String purchaseToken) {
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build();
billingClient.acknowledgePurchase(params, billingResult -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Toast.makeText(this, "Purchase Acknowledged", Toast.LENGTH_SHORT).show();
}
});
}
当我点击我的任何 [购买订阅] 按钮时,billingClient.launchBillingFlow(this, billingFlowParams);
被正确触发并且 SKU 是正确的。
据我所知,所有开发控制台都已正确设置。 我想向我的经理演示 IAP,但是,"The item you were attempting to purchase could not be found" 限制了我的风格! 我做错了什么?
我认为您的 loadAllSubscriptionProductIdDetails()
方法设计有误。
您只需在用户点击时调用 querySkuDetailsAsync()
,在 setSkusList()
参数中使用单个项目,即要购买的项目,然后:
@Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList.size() > 0) {
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(0))
.build();
billingClient.launchBillingFlow(activity, flowParams);
}
}
我在问题中发布的代码功能齐全。由于开发者控制台配置问题是 100% :
修复:
1) 将应用提升为 Alpha 版 最低(内部测试轨道不起作用!)
2) 单击 Alpha 轨道上的 [管理],然后通过电子邮件将选择加入 link 发送给您的测试人员
3) 您的测试人员会说 "when I click this link, the Play Store says the app isn't found"。告诉他们放松 30 分钟 - Google 控制台需要 30 分钟来处理这种复杂性。
让他们下载早期发布版本,IAP 突然就可以使用了!