谁能告诉我如何获取可供购买的产品列表?我正在使用简单的驱动器示例作为参考。假设在我的应用程序的开发者控制台上,我列出了两个产品作为产品 1 和产品 2。如何在我的应用程序。请帮助。
问问题
222 次
2 回答
0
我认为这应该是您正在寻找的:
http://developer.android.com/training/in-app-billing/list-iab-products.html#QueryDetails
于 2013-06-13T13:10:42.857 回答
0
尝试这个,
IabHelper billingHelper = new IabHelper(this, AppPublicKey.BASE_64_KEY);
billingHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
complain("Problem setting up in-app billing: " + result);
return;
}
// Have we been disposed of in the meantime? If so, quit.
if (billingHelper == null) return;
List<String> aListSKU = new ArrayList<String>();
aListSKU.add(ProductId.SKU100);
aListSKU.add(ProductId.SKU200);
aListSKU.add(ProductId.SKU400);
billingHelper.queryInventoryAsync(true, aListSKU, mGotInventoryListener);
}
});
创建 QueryInventoryFinishedListener 接口
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
// Have we been disposed of in the meantime? If so, quit.
if (billingHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
Toast.makeText(ProfileCreditActivity.this, "Failed to query inventory: " + result, Toast.LENGTH_SHORT).show();
return;
}
Log.d(TAG, "Query inventory was successful.");
SkuDetails sku100Details = inventory.getSkuDetails(ProductId.SKU100);
sku100Price = sku100Details.getPrice();
sku100Title = sku100Details.getTitle();
SkuDetails sku200Details = inventory.getSkuDetails(ProductId.SKU200);
sku200Price = sku200Details.getPrice();
sku200Title = sku100Details.getTitle();
SkuDetails sku400Details = inventory.getSkuDetails(ProductId.SKU400);
sku400Price = sku400Details.getPrice();
sku400Title = sku100Details.getTitle();
updateUI();
}
};
在此处更新您的用户界面
private void updateUI() {
}
于 2014-06-06T05:18:05.920 回答