簡體   English   中英

如何在Android 4.1和4.2上調試應用內結算?

[英]How to debug in-app billing on Android 4.1 and 4.2?

我是Android開發人員的新手,我遇到了一個非常煩人且熟悉的問題。

簡短版本 :如何在不購買物理設備的情況下測試我的應用程序? 具體來說,我正在嘗試在4.1和4.2運行的設備上進行測試。 我不能使用模擬器,因為這涉及應用內結算。

長版

今天,我收到了用戶的崩潰報告(Android版本= 4.2,設備= A1-811(芒果))。

問題是: 未設置IAB幫助程序。 無法執行操作:queryInventory 我在4.3、5.0、5.1上測試了該應用程序,這很好。

我知道發生了實際的崩潰,因為我在mhelper.startSetup()中檢查(!result.isSuccess())時沒有退出。

我的問題是,如何解決未設置IabHelper的根本問題? 我無權使用Android 4.2設備...

我的密碼:

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener () {
            public void onIabPurchaseFinished (IabResult result, Purchase purchase) {
                if (mHelper == null)
                    return;

                if (result.isFailure ()) {
                    Log.d (PURCHASE_TAG, "Google's response is a failure.");
                } else {
                    Log.d (PURCHASE_TAG, "Response is successful. purchase.getSKU = " + purchase.getSku ());
                    premium = true;
                }
            }
        };

        IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener () {
            public void onQueryInventoryFinished (IabResult result, Inventory inventory) {
                Log.d (PURCHASE_TAG, "Processing Google's response.");

                // Check if user has existing purchase.
                if (result.isFailure ()) {
                    Log.d (PURCHASE_TAG, "Google's response is a failure. Response = ");

                } else {
                    Log.d (PURCHASE_TAG, "Google's response is success! getPurchase() = " + inventory.getPurchase (THE_SKU));

                    if (inventory.getPurchase (THE_SKU) == null) {
                        premium = false;
                    } else {
                        premium = inventory.getPurchase (THE_SKU).getSku ().equals (THE_SKU);
                    }
                }

                // Show price if user is not premium, thank you note if the user is premium
                if (premium == true) {
                    Log.d (PURCHASE_TAG, "3 premium = " + premium);
                    priceView.setText ("Thank you for the purchase!");
                } else {
                    if (inventory != null) {
                        String pro_price = inventory.getSkuDetails (THE_SKU).getPrice ();
                        priceView.setText ("" + pro_price);
                    }
                }
            }
        };

        private void startPurchaseQuery () {
            String base64EncodedPublicKey = "the key is generated ...";

            mHelper = new IabHelper (this, base64EncodedPublicKey);

            Log.d (PURCHASE_TAG, "Purchase query started.");

            mHelper.startSetup (new IabHelper.OnIabSetupFinishedListener () {
                public void onIabSetupFinished (IabResult result) {
                    Log.d (PURCHASE_TAG, "IabHelper Setup successful. Querying inventory.");

                    if (!result.isSuccess ()) {
                        Log.d (PURCHASE_TAG, "Error with IabHelper setup.");
return;

                    }

                    if (mHelper == null) return;

                    // IAB is fully set up. Now, let's get an inventory of stuff we own.
                    // Build the SKU list
                    List<String> additionalSkuList;
                    additionalSkuList = new ArrayList<String> ();
                    additionalSkuList.add (THE_SKU);
                    // Make the query
                    mHelper.queryInventoryAsync (true, additionalSkuList, mQueryFinishedListener);

                    Log.d (PURCHASE_TAG, "Query finished. Premium status = " + premium);
                }
            });
        }


    @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data) {
        Log.d (PURCHASE_TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult (requestCode, resultCode, data)) {
            // not handled, so handle it ourselves (here's where you'd
            // perform any handling of activity results not related to in-app
            // billing...
            super.onActivityResult (requestCode, resultCode, data);
        } else {
            Log.d (PURCHASE_TAG, "onActivityResult handled by IABUtil.");
        }
    }



    @Override
    public void onDestroy () {
        super.onDestroy ();
        if (mHelper != null) mHelper.dispose ();
        mHelper = null;
    }

上面評論的答案

最好先捕獲錯誤並修補自己的代碼。 嘗試重現為什么未設置IAB的確切問題可能是不可能的,因為用戶可以在其設備上進行各種修改(可能是特定版本的發行版用戶正在運行的錯誤,這幾乎是找不到的,或者類似)。 如您所建議,使用Analytics(分析)找出有多少用戶遇到此問題是個好方法。

要回答原始問題,您可以在開發者控制台中創建Alpha或Beta版本,並將具有特定Android版本的用戶邀請到測試組中。 這是您可以直接從Dev測試問題和崩潰的方法。 即使不直接成為設備所有者,也要進行控制台。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM