android – mService.consumePurchase(3,packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERR...

栏目: IOS · Android · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/21758242/mservice-consumepurchase3-packagename-purchasetoken-always-returns-result-de

我总是得到“RESULT_DEVELOPER_ERROR = 5 – 提供给API的无效参数”,当试图消费购买时

String purchaseToken = "inapp:" + getPackageName() + ":" + productId;
int response = 0;
try {
    response = mService.consumePurchase(3, getPackageName(), purchaseToken);
} catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

出于这个原因,我总是只能购买一次.但是,我需要能够更频繁地进行购买.我一直试图解决这个问题2天,但没有成功. :/

使用SKU“android.test.purchased”制作和消费购买工作完全正常,但是只要我使用生产密钥导出.apk并添加实时SKU,购买只会显示一次,然后再也不会再显示.

这里有更多细节

> Play商店中.apk的版本代码和我在手机上使用的导出的.apk是相同的,并使用相同的密钥库进行签名

>我已经尝试过托管和非托管产品,但这无关紧要,因为 according to the latest in-app billing documentation ,托管和非托管被视为托管产品,两者都必须被消费

>我只有5个SKU项目,所以它没有达到20的限制,这是问题 here

购买令牌与SKU本身不同,您应该通过以下代码检索purchaseToken:
// Note the null is the continueToken you may not get all of the purchased items
// in one call - check ownedItems.getString("INAPP_CONTINUATION_TOKEN") for 
// the next continueToken and re-call with that until you don't get a token
Bundle ownedItems = service.getPurchases(3, getPackageName(), "inapp", null);
// Check response
int responseCode = ownedItems.getInt("RESPONSE_CODE");
if (responseCode != 0) {
   throw new Exception("Error");
}
// Get the list of purchased items
ArrayList<String> purchaseDataList = 
    ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String purchaseData : purchaseDataList) {
    JSONObject o = new JSONObject(purchaseData);
    String purchaseToken = o.optString("token", o.optString("purchaseToken"));
    // Consume purchaseToken, handling any errors
    mService.consumePurchase(3, getPackageName(), purchaseToken);
}

翻译自:https://stackoverflow.com/questions/21758242/mservice-consumepurchase3-packagename-purchasetoken-always-returns-result-de


以上所述就是小编给大家介绍的《android – mService.consumePurchase(3,packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERR...》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具