OmegaKi113r
OmegaKi113r

Reputation: 119

Implementing InApp Purchases

in OnCreate()

helper=new IabHelper(getApplicationContext(),base64EncodedPublicKey);
    helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            if(!result.isSuccess()){
                Log.d(TAG_BILLING,"In app failed "+result);
            }else{
                Log.d(TAG_BILLING,"billing success");
            }
        }
    });

button is attached to purchase function as follows.

try {
                helper.launchPurchaseFlow(MainActivity.this,ITEM_SKU,10001,purchasedFinishedListener,"my_purchase_token");
            } catch (IabHelper.IabAsyncInProgressException e) {
                e.printStackTrace();
            }


IabHelper.OnIabPurchaseFinishedListener purchasedFinishedListener=new IabHelper.OnIabPurchaseFinishedListener() {
    @Override
    public void onIabPurchaseFinished(IabResult result, Purchase info) {
        if(result.isFailure()){
            return;
        }else if(info.getSku().equals(ITEM_SKU)){

            try {
                helper.consumeAsync(info,consumedFinishedListener);
            } catch (IabHelper.IabAsyncInProgressException e) {
                e.printStackTrace();
            }

            //consumeItem();
            //mRootRef.child(userForDatabase.getUid()).child("Bought").setValue(10);
        }
    }
};




IabHelper.OnConsumeFinishedListener consumedFinishedListener=new IabHelper.OnConsumeFinishedListener() {
    @Override
    public void onConsumeFinished(Purchase purchase, IabResult result) {
        textView.setText(10);
    }
};

this is done following https://www.youtube.com/watch?v=vpnNEGOF3ck&list=PLvPqrYVmSBHeCbUccEYkkaqggtYkoJrXX

But by researching android developer website i found out that there are several ways to implement this.

In App Billing

What is the difference between these two. What should i do to implement In App Billing. What should i follow to implement from those two.

Upvotes: 1

Views: 380

Answers (1)

Nick Fortescue
Nick Fortescue

Reputation: 13842

Either will work, but the current recommended way from Google is to use the Play Billing class which has a complete training class on how to use it. This is the most modern and recommended way to add In-app billing according to Google Play, and will give you access to the latest features.

Upvotes: 1

Related Questions