[英]Google Play In-App Billing: Test purchase does not work + No product details available
I am trying to add Googles In-App Billing to my Android 4+ app. 我正在尝试将Googles应用内结算添加到我的Android 4+应用中。 I have set up everything as described in " Preparing Your In-app Billing Application ".
我已经按照“ 准备应用内结算应用程序 ”中所述进行了所有设置。 Now I have uploaded the app to the Alpha testing channel in the Developer console.
现在,我已将该应用程序上载到开发人员控制台中的Alpha测试频道。
Additionally I have set up a test account ( described here ) to be able purchase the items without triggering a real payment. 另外,我已经建立了一个测试帐户( 在此描述 ),可以在不触发实际付款的情况下购买商品。
After installing the alpha version from the Play Store on my test device (using the test account of course) there a two problems: 在我的测试设备上通过Play商店安装Alpha版本(当然使用测试帐户)后,出现两个问题:
No product information is fetched from the Play Store. 没有从Play商店获取产品信息。 Thus I cannot show any price information, etc.
因此,我无法显示任何价格信息等。
When I start a purchase there is absolutly no hint, that this will be a free test purchase. 当我开始购买时,没有任何暗示,这将是一次免费的测试购买。 Everything looks exactly like a real purchase.
一切看起来都像是真正的购买。
This is the code I use: 这是我使用的代码:
String publicKey = MyApp.getPublicKey(); // de-code and get the public key
final IabHelper googlePlayHelper = new IabHelper(context, publicKey);
Log.d("TAG", "IabHelber Init");
googlePlayHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d("TAG", "IabHelber Init - Non Success: " + result);
} else {
Log.d("TAG", "IabHelber Init - SUCCESS");
try {
googlePlayHelper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
Log.d("TAG", "query Inventory - Non Success: " + result);
} else {
Log.d("TAG", "query Inventory - SUCCESS");
if (inventory.hasDetails(2my.product.id")) {
Log.d("TAG", "NO DETAILS");
} else {
Log.d("TAG", "Has Details");
}
}
}
}
} catch (Exception e) {
Log.d("TAG", "EXCEPTION: " + e.getMessage());
}
}
}
});
The Log shows the following: 日志显示以下内容:
D/TAG (25995): IabHelber Init
D/TAG (25995): IabHelber Init - SUCCESS
D/TAG (25995): query Inventory - SUCCESS
D/TAG (25995): NO DETAILS
What could be the reason that now details are fetched? 现在获取详细信息的原因可能是什么? The docs that that there should be an hint when performing a test purchase.
在进行测试购买时应该有提示的文档。 Why am I runnig a "real" purchase instead?
为什么我会选择“真实”购买?
I have not been able to find out why purchases by test users are not handled as test purchases. 我无法找出为什么测试用户的购买不作为测试购买处理的原因。 But the problem with the missing product details is solved:
但是解决了缺少产品详细信息的问题:
I used the following call to query the inventory: 我使用以下调用查询库存:
googlePlayHelper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() { ... });
This is totally valid code and the first parameters (true in this example) states, that the query should fetch the product details. 这是完全有效的代码,第一个参数(在此示例中为true)指出查询应获取产品详细信息。 But it seems, that this parameter does not have any effect until a further parameter is given: One has to explicitly specify the IDs of the product one would like to fetch:
但是似乎该参数在给出另一个参数之前没有任何作用:必须明确指定要获取的产品的ID:
List<String> productIDs = new ArrayList<String>();
productIDs.add(IAP_ID_1);
productIDs.add(IAP_ID_2);
productIDs.add(IAP_ID_3);
googlePlayHelper.queryInventoryAsync(true, productIDs, new IabHelper.QueryInventoryFinishedListener() { ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.