Search in sources :

Example 1 with BillingClientStateListener

use of com.android.billingclient.api.BillingClientStateListener in project PhoneProfilesPlus 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(@BillingClient.BillingResponse int billingResponse) {
                if (billingResponse == BillingClient.BillingResponse.OK) {
                    if (executeOnSuccess == 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) DonationFragment(sk.henrichg.phoneprofilesplus.DonationFragment)

Example 2 with BillingClientStateListener

use of com.android.billingclient.api.BillingClientStateListener in project sms-backup-plus by jberkel.

the class DonationActivity method checkUserDonationStatus.

public static void checkUserDonationStatus(Context context, final DonationStatusListener listener) {
    final BillingClient helper = BillingClient.newBuilder(context).enablePendingPurchases().setListener(new PurchasesUpdatedListener() {

        @Override
        public void onPurchasesUpdated(BillingResult result, @Nullable List<Purchase> purchases) {
            log("onPurchasesUpdated(" + result + ", " + purchases + ")");
        }
    }).build();
    helper.startConnection(new BillingClientStateListener() {

        @Override
        public void onBillingSetupFinished(BillingResult result) {
            log("checkUserHasDonated: onBillingSetupFinished(" + result + ")");
            try {
                if (result.getResponseCode() == OK) {
                    PurchasesResult purchasesResult = helper.queryPurchases(INAPP);
                    if (result.getResponseCode() == OK) {
                        listener.userDonationState(userHasDonated(purchasesResult.getPurchasesList()) ? DONATED : NOT_DONATED);
                    } else {
                        listener.userDonationState(UNKNOWN);
                    }
                } else {
                    listener.userDonationState(result.getResponseCode() == BILLING_UNAVAILABLE ? NOT_AVAILABLE : UNKNOWN);
                }
            } finally {
                try {
                    helper.endConnection();
                } catch (Exception ignored) {
                }
            }
        }

        public void onBillingServiceDisconnected() {
        }
    });
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) PurchasesResult(com.android.billingclient.api.Purchase.PurchasesResult) PurchasesUpdatedListener(com.android.billingclient.api.PurchasesUpdatedListener) BillingResult(com.android.billingclient.api.BillingResult) ArrayList(java.util.ArrayList) List(java.util.List) BillingClient(com.android.billingclient.api.BillingClient) Nullable(androidx.annotation.Nullable)

Example 3 with BillingClientStateListener

use of com.android.billingclient.api.BillingClientStateListener in project scroball by peterjosling.

the class MainActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    billingClient = new BillingClient.Builder(this).setListener(this).build();
    billingClient.startConnection(new BillingClientStateListener() {

        @Override
        public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
            if (billingResponseCode == BillingResponse.OK) {
                Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
                onPurchasesUpdated(purchasesResult.getResponseCode(), purchasesResult.getPurchasesList());
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
        }
    });
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) BillingClient(com.android.billingclient.api.BillingClient)

Example 4 with BillingClientStateListener

use of com.android.billingclient.api.BillingClientStateListener in project sms-backup-plus by jberkel.

the class DonationActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    billingClient = BillingClient.newBuilder(this).setListener(this).enablePendingPurchases().build();
    billingClient.startConnection(new BillingClientStateListener() {

        @Override
        public void onBillingSetupFinished(BillingResult resultCode) {
            log("onBillingSetupFinished(" + resultCode + ")" + Thread.currentThread().getName());
            switch(resultCode.getResponseCode()) {
                case OK:
                    queryAvailableSkus();
                    break;
                case BILLING_UNAVAILABLE:
                case DEVELOPER_ERROR:
                case ERROR:
                case FEATURE_NOT_SUPPORTED:
                case ITEM_ALREADY_OWNED:
                case ITEM_NOT_OWNED:
                case ITEM_UNAVAILABLE:
                case SERVICE_DISCONNECTED:
                case SERVICE_UNAVAILABLE:
                case USER_CANCELED:
                case SERVICE_TIMEOUT:
                default:
                    Toast.makeText(DonationActivity.this, R.string.donation_error_iab_unavailable, LENGTH_LONG).show();
                    Log.w(TAG, "Problem setting up in-app billing: " + resultCode);
                    finish();
                    break;
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            Log.d(TAG, "onBillingServiceDisconnected");
        }
    });
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) BillingResult(com.android.billingclient.api.BillingResult)

Example 5 with BillingClientStateListener

use of com.android.billingclient.api.BillingClientStateListener 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)

Aggregations

BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)6 BillingResult (com.android.billingclient.api.BillingResult)4 BillingClient (com.android.billingclient.api.BillingClient)2 Nullable (androidx.annotation.Nullable)1 PurchasesResult (com.android.billingclient.api.Purchase.PurchasesResult)1 PurchasesUpdatedListener (com.android.billingclient.api.PurchasesUpdatedListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DonationFragment (sk.henrichg.phoneprofiles.DonationFragment)1 DonationFragment (sk.henrichg.phoneprofilesplus.DonationFragment)1