我从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 + "\n\n";
} 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();
}
答案 0 :(得分:1)
测试ID不会在后端存储购买状态信息,因此您无法使用它们获取数据。因此,为了使实际购买历史记录有效,您应该使用您为诺基亚商店中的内容预留的真实ID。还要记住等到ID尝试使用它们之前已经通过了QA。