我正在尝试在应用程序结算中实现.我已经使用了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.
在尝试实现Android应用内购买(IAB)功能时,开发者遇到一个问题:在代码中注释掉`mHelper.queryInventoryAsync(mGotInventoryListener);`导致无法查询库存。尽管IAB设置显示成功,但`IabHelper`的`mSetupDone`变量保持为false,引发了`Illegalstateforoperation(queryInventory)`异常。问题可能在于初始化或回调处理不正确,需要进一步调试和修复设置流程以确保能成功查询库存。
5241

被折叠的 条评论
为什么被折叠?



