如何获取 SKU 价格并将其显示在 TextView 中
How to get a SKU price and display it in a TextView
我需要检索我的 InApp Purchase 的价格并将其作为标题显示在我的卡片布局中。
这是卡片的样子,而不是"sku price",我需要有实际价格。
我只有这个 IAP,所以我不需要数组或列表。
为了在 App Billing 中实施,我遵循了 Android Developers - In App Billing Guide
到目前为止,我试图在我的 onQueryInventoryFinished()
方法中编写它,但没有任何运气。
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
//have we been disposed of in the meantime? if so, quit
if (mHelper == null) return;
//is it a failure?
if(result.isFailure()) {
alert("Failed to query Inventory: " + result);
return;
}
String skuPrice = inv.getSkuDetails(SKU_PREMIUM).getPrice();
((TextView)findViewById(R.id.card_buy_title)).setText(skuPrice);
//do we have the premium upgrade?
Purchase premiumPurchase = inv.getPurchase(SKU_PREMIUM);
isPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
}
};
据我所知,我所做的这件事应该得到已购买物品的价格。所以也许这就是它不起作用的原因。
你们谁能指出我正确的方向吗?
在您的 mHelper 设置中,您必须通过调用
来查询所有库存
mHelper.queryInventoryAsync(true, allSkus, null, mGotInventoryListener);
其中 allSkus 是所有 sku 的列表。
检查IabHelper。
我需要检索我的 InApp Purchase 的价格并将其作为标题显示在我的卡片布局中。
这是卡片的样子,而不是"sku price",我需要有实际价格。
我只有这个 IAP,所以我不需要数组或列表。
为了在 App Billing 中实施,我遵循了 Android Developers - In App Billing Guide
到目前为止,我试图在我的 onQueryInventoryFinished()
方法中编写它,但没有任何运气。
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
//have we been disposed of in the meantime? if so, quit
if (mHelper == null) return;
//is it a failure?
if(result.isFailure()) {
alert("Failed to query Inventory: " + result);
return;
}
String skuPrice = inv.getSkuDetails(SKU_PREMIUM).getPrice();
((TextView)findViewById(R.id.card_buy_title)).setText(skuPrice);
//do we have the premium upgrade?
Purchase premiumPurchase = inv.getPurchase(SKU_PREMIUM);
isPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
}
};
据我所知,我所做的这件事应该得到已购买物品的价格。所以也许这就是它不起作用的原因。
你们谁能指出我正确的方向吗?
在您的 mHelper 设置中,您必须通过调用
来查询所有库存mHelper.queryInventoryAsync(true, allSkus, null, mGotInventoryListener);
其中 allSkus 是所有 sku 的列表。
检查IabHelper。