![](/img/trans.png)
[英]Android in app purchase: BillingClient: getPurchase() failed. Response code: 3
[英]mService.getPurchase always returning 0 owned items, even after in app subscription purchase
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版本中有效,还是可以通过在Studio中运行应用进行调试?
因为,用户已经购买了应用程序内订阅,但是在调试过程中,我仍然仅获得“ INAPP_PURCHASE_ITEM_LIST”的0个项目。
请有人帮我。
对于订阅情况,您需要将请求的项目类型从inapp
为subs
:
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "subs", null);
在这种情况下,您只会看到订阅。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.