gpt4 book ai didi

android - 在应用内结算 IAB 设置成功但 queryInventory 报告 IAB 助手未设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:22 26 4
gpt4 key购买 nike

我正在尝试在应用计费中实现。我按原样使用了 trivialdrivesample。

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// load game data
loadData();


String base64EncodedPublicKey = "my key";



// Create the helper, passing it our context and the public key to verify signatures with
Log.d(TAG, "Creating IAB helper.");
mHelper = new IabHelper(this, base64EncodedPublicKey);

// enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(true);

// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");

if (!result.isSuccess()) {
// Oh noes, there was a problem.
complain("Problem setting up in-app billing: " + result);
return;
}

// Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d(TAG, "Setup successful. Querying inventory.");
// mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
}

Button purchaseB = (Button)findViewById(R.id.purchase_button);

if(purchaseB != null)
purchaseB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

onUpgradeAppButtonClicked(null);

}
});

它运行良好,我可以从我的测试帐户购买。

但问题是我必须注释代码行

//mHelper.queryInventoryAsync(mGotInventoryListener);所以我无法查询库存。在调试时我发现了那个变量

// Is setup done?
boolean mSetupDone = false;

在 IabHelper 类中为 false 并引发异常。说设置成功后的日志说 IAB 助手未设置。


08-02 16:02:42.453: D/PackList(10346): Creating IAB helper.
08-02 16:02:42.453: D/PackList(10346): Starting setup.
08-02 16:02:42.468: D/IabHelper(10346): Starting in-app billing setup.
08-02 16:02:42.515: D/PackList(10346): Creating IAB helper.
08-02 16:02:42.539: D/IabHelper(10346): Billing service connected.
08-02 16:02:42.546: D/IabHelper(10346): Checking for in-app billing 3 support.
08-02 16:02:42.562: D/IabHelper(10346): In-app billing version 3 supported for com.xx
08-02 16:02:42.570: D/IabHelper(10346): Subscriptions AVAILABLE.
08-02 16:02:42.570: D/PackList(10346): Setup finished.
08-02 16:02:42.570: D/PackList(10346): Setup successful. Querying inventory.
08-02 16:02:42.578: E/IabHelper(10346): In-app billing error: Illegal state for operation (queryInventory): IAB helper is not set up.

最佳答案

试试这个。

设置:

mIabHelper = new IabHelper(this, ProjectKonstants.APP_PUBLIC_KEY_GOOGLE_PLAY);

mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
public void onIabSetupFinished(IabResult result)
{
if (result.isSuccess())
{
mIabHelper.queryInventoryAsync(mInitialInventoryListener);
}
}
});

mInitialInventoryListener = new IabHelper.QueryInventoryFinishedListener()
{
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isSuccess())
{
mBHasDonated = inventory.hasPurchase(ProjectKonstants.APPLICATION_SKU_FOR_DONATION);
}
else
{
mBHasDonated = false;
}
}
};

mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isSuccess())
{
if (purchase.getSku().equals(ProjectKonstants.APPLICATION_SKU_FOR_DONATION))
{
mBHasDonated = true;
return;
}
}
mBHasDonated = false;
}
};

点击升级按钮时:

AccountManager accountManager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] accounts = accountManager.getAccounts();
String strIdentifier = "[" + accounts[0].name + "][" + android.os.Build.MODEL + "][" + android.os.Build.VERSION.RELEASE + "]";
try
{
mIabHelper.launchPurchaseFlow(this, ProjectKonstants.APPLICATION_SKU_FOR_DONATION, 10001, mPurchaseFinishedListener, strIdentifier);
}
catch (IllegalStateException e)
{
}

关于android - 在应用内结算 IAB 设置成功但 queryInventory 报告 IAB 助手未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18015170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com