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