Search in sources :

Example 26 with BillingResult

use of com.android.billingclient.api.BillingResult in project PhoneProfiles by henrichg.

the class BillingManager method startServiceConnectionIfNeeded.

private void startServiceConnectionIfNeeded(final Runnable executeOnSuccess) {
    // PPApplication.logE(TAG, "startServiceConnectionIfNeeded");
    if (mBillingClient.isReady()) {
        if (executeOnSuccess != null) {
            executeOnSuccess.run();
        }
    } else {
        DonationFragment fragment = getFragment();
        if (fragment != null)
            fragment.setWaitScreen(true);
        mBillingClient.startConnection(new BillingClientStateListener() {

            @Override
            public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    if (executeOnSuccess == null) {
                        if (getFragment() != null)
                            getFragment().updateGUIAfterBillingConnected();
                    }
                    if (executeOnSuccess != null) {
                        executeOnSuccess.run();
                    }
                }
            /*else {
                        Log.w(TAG, "onBillingSetupFinished() error code: " + billingResponse);
                    }*/
            }

            @Override
            public void onBillingServiceDisconnected() {
            // Log.w(TAG, "onBillingServiceDisconnected()");
            }
        });
    }
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) BillingResult(com.android.billingclient.api.BillingResult) DonationFragment(sk.henrichg.phoneprofiles.DonationFragment)

Example 27 with BillingResult

use of com.android.billingclient.api.BillingResult in project PhoneProfiles by henrichg.

the class BillingManager method querySkuDetailsAsync.

public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {

        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams, new SkuDetailsResponseListener() {

                @Override
                public void onSkuDetailsResponse(@NonNull BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(billingResult, skuDetailsList);
                }
            });
        }
    };
    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams) BillingResult(com.android.billingclient.api.BillingResult)

Example 28 with BillingResult

use of com.android.billingclient.api.BillingResult in project apcupsd-monitor by norkator.

the class MainMenu method initInAppBilling.

// ---------------------------------------------------------------------------------------------
/* In app billing features */
// Initialize in app billing feature
private void initInAppBilling() {
    // In app billing
    mBillingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build();
    mBillingClient.startConnection(new BillingClientStateListener() {

        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
            // The billing client is ready. You can query purchases here.
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
        }
    });
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) BillingResult(com.android.billingclient.api.BillingResult)

Aggregations

BillingResult (com.android.billingclient.api.BillingResult)28 SkuDetails (com.android.billingclient.api.SkuDetails)16 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)15 ArrayList (java.util.ArrayList)14 BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)10 ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)10 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)10 List (java.util.List)10 NonNull (androidx.annotation.NonNull)9 ConsumeParams (com.android.billingclient.api.ConsumeParams)9 Purchase (com.android.billingclient.api.Purchase)9 AcknowledgePurchaseResponseListener (com.android.billingclient.api.AcknowledgePurchaseResponseListener)8 Nullable (androidx.annotation.Nullable)7 AcknowledgePurchaseParams (com.android.billingclient.api.AcknowledgePurchaseParams)7 BillingClient (com.android.billingclient.api.BillingClient)7 BillingFlowParams (com.android.billingclient.api.BillingFlowParams)7 PurchasesUpdatedListener (com.android.billingclient.api.PurchasesUpdatedListener)7 Activity (android.app.Activity)5 Context (android.content.Context)5 StringRes (androidx.annotation.StringRes)5