android – mService.consumePurchase(3,packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERROR = 5 – 提供给API的无效参数

我总是得到“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,"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,purchasetoken);
}

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...