简体   繁体   English

如何在Android 4.1和4.2上调试应用内结算?

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

New to Android dev and I have this very annoying, and familiar problem. 我是Android开发人员的新手,我遇到了一个非常烦人且熟悉的问题。

Short version : how can I test my app on multiple physical devices w/o buying them? 简短版本 :如何在不购买物理设备的情况下测试我的应用程序? Specifically, I'm trying to test on 4.1 and 4.2 running devices. 具体来说,我正在尝试在4.1和4.2运行的设备上进行测试。 I can't use an emulator because this involves in-app billing. 我不能使用模拟器,因为这涉及应用内结算。

Long version : 长版

Today, I got a crash report from a user (android version = 4.2, on device = A1-811 (mango)). 今天,我收到了用户的崩溃报告(Android版本= 4.2,设备= A1-811(芒果))。

The issue is: IAB helper is not set up. 问题是: 未设置IAB帮助程序。 Can't perform operation: queryInventory . 无法执行操作:queryInventory I tested the app on 4.3, 5.0, 5.1 and it's fine. 我在4.3、5.0、5.1上测试了该应用程序,这很好。

I KNOW that the actual crash happened because I wasn't quitting when I was checking for (!result.isSuccess()) in mhelper.startSetup(). 我知道发生了实际的崩溃,因为我在mhelper.startSetup()中检查(!result.isSuccess())时没有退出。

My question is, how do I solve the underlying issue of IabHelper not being set up?! 我的问题是,如何解决未设置IabHelper的根本问题? I don't have access to Android 4.2 device... 我无权使用Android 4.2设备...

MY CODE: 我的密码:

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;
    }

Answer from comments above 上面评论的答案

It's better to catch the error and patch own code first. 最好先捕获错误并修补自己的代码。 Trying to reproduce exact issue why was IAB not set up may not be possible, because of all kinds of modifications user can do on his device (could be bug with specific version of distro user is running, which is almost impossible to find out, or similar). 尝试重现为什么未设置IAB的确切问题可能是不可能的,因为用户可以在其设备上进行各种修改(可能是特定版本的发行版用户正在运行的错误,这几乎是找不到的,或者类似)。 As you suggested, using Analytics to find out how many users have this issue is good approach. 如您所建议,使用Analytics(分析)找出有多少用户遇到此问题是个好方法。

To answer original question, you can create Alpha or Beta versions in Developer Console and invite users with specific versions of Android you'd like to target into testing group. 要回答原始问题,您可以在开发者控制台中创建Alpha或Beta版本,并将具有特定Android版本的用户邀请到测试组中。 This was you could test issues and crashes directly from Dev. 这是您可以直接从Dev测试问题和崩溃的方法。 Console even when not directly being owner of the device. 即使不直接成为设备所有者,也要进行控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM