我在网上找到了这个代码。您是否认为它实际上可以释放我的托管项目并使其可以再次购买或是否需要进行一些修改?好像我无法正确测试它。看起来我需要一个测试按钮来释放我所有的托管项目。我是在正确的轨道上还是完全被误导了?我只需要一个意见,请您不必发布您的托管项目......
public void consumeAllOlderItems() {
Bundle ownedItems = null;
try {
ownedItems = mHelper.mService.getPurchases(3, sGame.getContext().getPackageName(), "inapp", null);
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0)
{
alertNonStatic("consumeAllOlderItems() google responded ok to our consumables");
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
//String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
if(purchaseDataList != null && purchaseDataList.size() > 0)
for (int i = 0; i < purchaseDataList.size(); ++i) {
try {
String purchaseData = purchaseDataList.get(i);
JSONObject jo = new JSONObject(purchaseData);
if(jo != null && jo.length() > 0);
final String token = jo.getString("purchaseToken");
String sku = null;
String sig = null;
if (ownedSkus != null){
sku = ownedSkus.get(i);
if (signatureList != null && signatureList.size() > 0){
sig = signatureList.get(i);
}
consume(sku, token, purchaseData,sig);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
else if(response != 0){
alertNonStatic("Response for older items is "+response);
}
}
private void consume(String sku, String token, String purchaseData,String sig) {
alertNonStatic("consume is trying to consume an item");
Purchase purchace = null;
try {
purchace = new Purchase("inapp", purchaseData, sig);
} catch (JSONException e) {
e.printStackTrace();
}
mHelper.consumeAsync(purchace,mConsumeFinishedListener);
}
答案 0 :(得分:0)
没有理由重新创建购买对象以使用consumeAsync,因为谷歌文档上的推荐说要生成一个新的线程并且已经结束:
int response = mService.consumePurchase(3,getPackageName(),token);