我从getProductDetails()中获得了一些产品id的详细信息。我成功地购买了前三个测试产品。但我无法从getPurchases()中获取已购买的产品列表。
================================================
public void getThePurchasedItem(ArrayList<String> productQuery){
final Bundle queryBundle = new Bundle();
queryBundle.putStringArrayList("ITEM_ID_LIST", productQuery);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
String continuationToken = null;
Bundle ownedItems = null;
try {
showToast("getThePurchasedItem 0000000");
ownedItems = mService.getPurchases(BILLING_API_VERSION, getPackageName(), ITEM_TYPE_INAPP, queryBundle, continuationToken);
showToast("getThePurchasedItem 1111111");
// ownedItems = mService.getPurchases(BILLING_API_VERSION, getPackageName(), ITEM_TYPE_INAPP, null, null);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int response = ownedItems.getInt("RESPONSE_CODE");
showToast("response code:"+response);
if (response == RESULT_OK) {
ArrayList<String> ownedProducts = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
System.out.println("getPurchasedItem data size:"+purchaseDataList.size());
System.out.println("getPurchasedItem item size:"+ownedItems.size());
String data = "";
showToast("purchaseDataList.size():"+purchaseDataList.size());
showToast("ownedProducts.size():"+ownedProducts.size());
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
String product = ownedProducts.get(i);
System.out.println("product:"+product);
System.out.println("purchaseData:"+purchaseData);
/*purchaseData look like this
{
"productId": "YourProductID",
"purchaseToken": "XDd333xk38s",
"developerPayload": ""
}*/
try {
JSONObject jsonPurchaseData = new JSONObject(purchaseData);
String productId = jsonPurchaseData.getString("productId");
String developerPayload = jsonPurchaseData.getString("developerPayload");
String purchaseToken = jsonPurchaseData.getString("purchaseToken");
lastObtainedPurchaseToken = purchaseToken;
System.out.println("productId:"+productId);
System.out.println("developerPayload:"+developerPayload);
System.out.println("purchaseToken:"+purchaseToken);
data += "=============================n";
data +="nproductId:"+productId + "n";
data +="developerPayload:"+developerPayload + "n";
data +="purchaseToken:"+purchaseToken + "nn";
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// do something with this purchase information
// e.g. display the updated list of products owned by user
}
data += "=============================";
if(purchaseDataList.size()==0){
data="No one product purchased";
}
final String finalData = data;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
textview.setText(finalData);
}
});
}else{
System.out.println("getPurchasedItem failed:"+response);
}
}
}).start();
}
测试ID没有在后端存储购买状态信息,因此您无法使用它们获取数据。因此,要使实际的购买历史记录正常工作,您应该使用您在诺基亚商店为您的内容保留的真实ID。还要记住,在尝试使用ID之前,要等到ID通过QA。