Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

android - mService.consumePurchase(3, packageName, purchaseToken) always returns RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API

I'm always getting "RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API", when trying to consume a purchase with

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();
}

For that reason, I can always only make a purchase once. However, I need to be able to make the purchase much more often. I've been trying to fix this problem for 2 days now, no success. :/

Making and consuming purchases with SKU "android.test.purchased" works completely fine, however as soon as I export the .apk with the production key and add a live SKU, the purchase only shows up once and then never again.

Here some more details

  1. The version code of the .apk in the play store and the exported .apk I'm using on my phone are the same and were signed with the same keystore
  2. I've tried it for both managed and unmanaged products, however that shouldn't matter, because according to the latest in-app billing documentation, managed and unmanaged are treated as managed products and both have to be consumed
  3. I only have 5 SKU items, so it doesn't hit the limit of 20, which was the problem here
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The purchase token is different from the SKU itself, instead, you should retrieve the purchaseToken via code such as:

// 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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...