android billing:4.0.0 - queryPurchases(INAPP) and purchase.getSku()
2022-09-01 04:29:39
我刷新到Android计费版本4和2的东西不再工作。
首先我有这个:
else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
Purchase.PurchasesResult queryAlreadyPurchasesResult = billingClient.queryPurchases(INAPP); // deprecated
List<Purchase> alreadyPurchases = queryAlreadyPurchasesResult.getPurchasesList();
if(alreadyPurchases!=null){
handlePurchases(alreadyPurchases);
}
}
queryPurchases 已被弃用。
其次,我有这个:
void handlePurchases(List<Purchase> purchases) {
for(Purchase purchase:purchases) {
//if item is purchased
if (PRODUCT_ID.equals(purchase.getSku()) && purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED)
{
if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
// Invalid purchase
// show error to user
Toast.makeText(getApplicationContext(), R.string.plus_error, Toast.LENGTH_SHORT).show();
return;
}
getSku() 工作正常,但现在它被标记为Cannot resolve method getSku() in Purchase
有什么想法如何解决这个问题?
来自文档:
Summary of changes
Added BillingClient.queryPurchasesAsync() to replace BillingClient.queryPurchases() which will be removed in a future release.
Added Purchase#getSkus() and PurchaseHistoryRecord#getSkus(). These replace Purchase#getSku and PurchaseHistoryRecord#getSku which have been removed.
但是我不知道如何在上面的代码中应用这个新命令。
如果我将getSku更改为getSkus,我的if会说它总是假的。我不知道如何使用queryPurchasesAsync(),现在需要2个参数。if (PRODUCT_ID.equals(purchase.getSkus()) && purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED)
谢谢。