在尝试使用
进行购买时,我总是收到“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,购买只会显示一次,然后再显示一次。
这里有更多细节
答案 0 :(得分:24)
购买令牌与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);
}
答案 1 :(得分:0)
我刚刚发现如果你为getSkuDetails向ITEM_ID_LIST添加超过20个项目,那么它也将返回RESULT_DEVELOPER_ERROR。