【问题标题】:How to leave in-app-billing-purchase within a class如何在课程中留下应用内计费购买
【发布时间】:2017-10-05 16:59:33
【问题描述】:

我已经在我的应用程序中集成了“in-app-billing-purchase”,但是我有几个活动需要复制所有代码。

所以我想把所有的事情都集中在一个班级上,我浪费了这个班级,如果物品被买了我就到了。

只是我有一个大问题,“应用内计费购买”使用监听器 OnIabPurchaseFinishedListenerQueryInventoryFinishedListener

我怎样才能把所有这些都安排在一个班级中,然后在我的活动中通过一个简单的调用来检查?

调用代码:

Billing bl = new Billing(getActivity().getApplicationContext());
if (bl.Comprado())
    Toast.makeText(getActivity(), "Comprado", Toast.LENGTH_SHORT).show();
else
    Toast.makeText(getActivity(), "Erro comprado", Toast.LENGTH_SHORT).show();

我创建的类要被多次调用

public class Billing {
// Item name for premium status
private static final String SKU_PREMIUM = "premium";
// private static final String SKU_PREMIUM = "tirarbanner";
// Flag set to true when we have premium status
private static boolean mIsPremium = false;
// In-app Billing helper
private IabHelper mAbHelper;

public Billing(Context context) {

    String base64EncodedPublicKey = "xxx";
    // Create in-app billing helper
    mAbHelper = new IabHelper(context, base64EncodedPublicKey);
    // and start setup. If setup is successfull, query inventory we already
    // own
    mAbHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {

            if (!result.isSuccess()) {
                return;
            }
            mAbHelper.queryInventoryAsync(mGotInventoryListener);
        }
    });
}

public static boolean Comprado() {
    return mIsPremium;
}

/**
 * Listener that is called when we finish purchase flow.
 */
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

        if (result.isFailure()) {
            return;
        }
        // Purchase was successfull, set premium flag and update interface
        if (purchase.getSku().equals(SKU_PREMIUM)) {
            mIsPremium = true;
        }
    }
};

/**
 * Listener that's called when we finish querying the items and
 * subscriptions we own
 */
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

        // Have we been disposed of in the meantime? If so, quit.
        if (mAbHelper == null)
            return;

        // Is it a failure?
        if (result.isFailure()) {
            return;
        }

        // Do we have the premium upgrade?
        Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
        mIsPremium = premiumPurchase != null;

    }
};

}

【问题讨论】:

    标签: java android in-app-billing


    【解决方案1】:

    已经有一个库。

    查看android-inapp-billing-v3.

    【讨论】:

    • 但是我已经使用了我需要的库,而不是使用相同的代码来集中我班级中的所有内容
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多