通过IAP购买的SKU不会在同一用户拥有的第二台设备上购买

时间:2014-11-17 15:33:35

标签: android in-app-purchase

我经常得到这个投诉,以至于用户使用IAP购买我的高级功能,并且它在他们购买的设备上工作正常,但他们的其他设备无法获得这些功能,我请他们重新启动其他设备通常修复它。所以前几天我试着看看我是否可以对此做点什么,所以我在我的一个设备上购买(测试帐号),然后我去了另一个,杀了我的应用程序,以确保它从零开始,然后步代码。购买的查询实际上没有回购。在我试图从该设备购买保险费之前,它没有告诉我购买情况。试图从该设备购买溢价没有创建一个对话框或任何东西,它只是返回,好像什么也没发生,但在此之后,设备在其库存上进行了购买。

以下是我的方法,我正在使用Google示例中的IABHelper,我想我在一个月前更新了它。

public void createIABHelper(final Context ac) {
        mHelper = new IabHelper(ac, myid);
        try {
            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                public void onIabSetupFinished(IabResult result) {
                    if (!result.isSuccess()) {
                        // Oh noes, there was a problem.
                        Log.d(TAG, "Problem setting up In-app Billing: " + result);

                    } else {
                        iabSetup = true;
                        //queryIAB(ac);
                        queryIABPurchases(ac);

                    }
                }
            });
        } catch (Throwable e) {
            final String desc = "Error starting IABHelper";
            Log.w(TAG, desc, e);

        }

    }


public void queryIAB(final Context ctx) {

        List<String> additionalSkuList = new ArrayList<String>();
        additionalSkuList.add(Constants.PREMIUM_UPGRADE);

        IabHelper.QueryInventoryFinishedListener
                mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
                if (result.isFailure()) {
                    // handle error
                    return;
                } else {
                    Purchase p = inventory.getPurchase(Constants.PREMIUM_UPGRADE);
                    if (p != null) {

                        setHasPremiumPref(p.getPurchaseState() == 0);
                    } else {
                        setHasPremiumPref(false);
                    }
                }
                // inventory.hasDetails(PREMIUM_UPGRADE);


                // update the UI
            }
        };
        mHelper.queryInventoryAsync(true, additionalSkuList,
                mQueryFinishedListener);
    }

    @Override
    public void purchaseIAB(final Activity ac) {
        if (iabSetup) {
            try {


                final String finalPayload = ....;
                IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
                        = new IabHelper.OnIabPurchaseFinishedListener() {
                    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                        if (result.isFailure()) {
                            Log.d(TAG, "Error purchasing: " + result);
                            return;
                        } else if (purchase.getSku().equals(Constants.PREMIUM_UPGRADE)) {
                            Log.w(TAG, "Purchased " + purchase.getPurchaseState());
                            if (purchase.getDeveloperPayload().equals(finalPayload) && purchase.getPurchaseState() == 0) {

                                setHasPremiumPref(true);
                            } else {
                                Log.w(TAG, "Something went wrong verifying purchase.");

                                setHasPremiumPref(false);

                            }
                        }

                    }
                };

                mHelper.launchPurchaseFlow(ac, Constants.PREMIUM_UPGRADE, 10001,
                        mPurchaseFinishedListener, finalPayload);
            } catch (Throwable ex) {
                final String msg = "Error starting in-app purchase";
                Log.w(TAG, msg, ex);

            }
        } else {
            Log.w(TAG, "IAB not setup.");
        }
    }

public void queryIABPurchases(Context ctx) {
        if (iabSetup) {
            IabHelper.QueryInventoryFinishedListener mGotInventoryListener
                    = new IabHelper.QueryInventoryFinishedListener() {
                public void onQueryInventoryFinished(IabResult result,
                                                     Inventory inventory) {

                    if (result.isFailure()) {
                        // handle error here
                    } else {
                        // does the user have the premium upgrade?
                        Purchase p = inventory.getPurchase(Constants.PREMIUM_UPGRADE);
                        if (p != null) {

                            setHasPremiumPref(p.getPurchaseState() == 0);
                        } else {
                            setHasPremiumPref(false);
                        }

                        // update UI accordingly
                    }

                }
            };
            List<String> additionalSkuList = new ArrayList<String>();
            additionalSkuList.add(Constants.PREMIUM_UPGRADE);
            mHelper.queryInventoryAsync(false, additionalSkuList, mGotInventoryListener);
        } else {
            Log.w(TAG, "IAB not setup.");


        }

    }

无论如何,基本上我使用queryIABPurchasesp在第二个设备上始终为空。这是测试帐户的问题还是与时间有关,我可能需要等待几个小时才能在第二台设备上测试吗?

感谢。

0 个答案:

没有答案