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.xx08-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设置成功,但quaryInventory报告IAB帮手没有设置全部内容,希望文章能够帮你解决android – 在应用程序计费IAB设置成功,但quaryInventory报告IAB帮手没有设置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)