try{
Bundle ownedItems = mService.getPurchases(3, getPackageName(),
"inapp", null);
if (ownedItems != null) {
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList ownedSkus = ownedItems
.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList purchaseDataList = ownedItems
.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList signatureList = ownedItems
.getStringArrayList("INAPP_DATA_SIGNATURE");
String continuationToken = ownedItems
.getString("INAPP_CONTINUATION_TOKEN");
for (int i = 0; i < purchaseDataList.size(); ++i) {
String signature = null;
String purchaseData = (String) purchaseDataList.get(i);
if (signatureList != null)
signature = (String) signatureList.get(i);
String sku = (String) ownedSkus.get(i);
Log.d(TAG, "::isPremium:" + "sku:" + sku);
Log.d(TAG, "::isPremium:" + "purchaseData:"
+ purchaseData);
Log.d(TAG, "::isPremium:" + "signature:" + signature);
if (sku.equalsIgnoreCase(SKU_PREMIUM)) {
Log.d(TAG, "::isPremium:" + "Already Purchased");
return true;
}
// do something with this purchase information
// e.g. display the updated list of products owned by
// user
}
// if continuationToken != null, call getPurchases again
// and pass in the token to retrieve more items
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
上面的代码是否仅适用于Alpha版本,或者我是否可以通过在工作室中运行app来调试它。
因为用户已经购买了应用内订阅,但在调试过程中我只能获得“INAPP_PURCHASE_ITEM_LIST”的0项。
请有人帮我解决这个问题。
答案 0 :(得分:0)
对于订阅案例,您需要将所请求的项目类型从inapp
更改为subs
:
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "subs", null);
在这种情况下,您只会看到响应中的订阅。