From 1dbf3d39e27dd318b210ef7b825217b7579c7a75 Mon Sep 17 00:00:00 2001 From: Devesh Chaudhari Date: Mon, 4 Sep 2023 22:07:44 +0530 Subject: [PATCH 1/2] bug fixed Signed-off-by: Devesh --- app/build.gradle | 2 +- app/proguard-rules.pro | 7 ++++++- billing/build.gradle | 2 +- billing/proguard-rules.pro | 6 +++++- build.gradle | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7d26ebe..2bed409 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -197,7 +197,7 @@ dependencies { // def billing_version = "5.2.0" def billing_version = "6.0.1" - implementation "com.android.billingclient:billing:$billing_version" + implementation "com.android.billingclient:billing:$project.billing_version" implementation "com.google.android.gms:play-services-base:$project.play_services_base" implementation 'com.google.android.ump:user-messaging-platform:2.1.0' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 1c25e7f..0dc5613 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -30,4 +30,9 @@ # Modify this rule to fit the structure of your app. -keepclassmembers class devesh.app.ocr.** { *; -} \ No newline at end of file +} + +-keepclassmembers class com.android.billingclient.api.** { + *; +} + diff --git a/billing/build.gradle b/billing/build.gradle index 1b6e25d..4763912 100644 --- a/billing/build.gradle +++ b/billing/build.gradle @@ -42,7 +42,7 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' def billing_version = "6.0.1" - api "com.android.billingclient:billing:$billing_version" + api "com.android.billingclient:billing:$project.billing_version" api "com.google.android.gms:play-services-base:$project.play_services_base" } \ No newline at end of file diff --git a/billing/proguard-rules.pro b/billing/proguard-rules.pro index 481bb43..c9cb9b3 100644 --- a/billing/proguard-rules.pro +++ b/billing/proguard-rules.pro @@ -18,4 +18,8 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +-keepclassmembers class com.android.billingclient.api.** { + *; +} diff --git a/build.gradle b/build.gradle index ea698f1..d97c657 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,7 @@ project.ext{ gson_version="2.10.1" glide_version="4.14.0" play_services_base="18.2.0" + billing_version = "6.0.1" AdMobAppID=AdMob_App_ID AdMobAdBannerID1=AdMob_AdBannerID1 From 2a39ab984eca6208d16c67fbf2cc1b00a7c25a49 Mon Sep 17 00:00:00 2001 From: Devesh Date: Thu, 7 Sep 2023 16:25:23 +0530 Subject: [PATCH 2/2] billing issue fixed --- app/build.gradle | 5 +- .../devesh/app/billing/BillingActivity.java | 46 +++++++++++++++---- .../java/devesh/app/billing/GPlayBilling.java | 8 +++- .../main/java/devesh/app/common/AdMobAPI.java | 33 ++++++++++++- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2bed409..c29e27c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ plugins { } -def AppVersionCode = 7 -def AppVersionName = "1.0.0.7" +def AppVersionCode = 8 +def AppVersionName = "1.0.0.8" android { compileSdk project.CompileSDK @@ -80,6 +80,7 @@ android { signingConfig signingConfigs.release minifyEnabled true shrinkResources true + // debuggable true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' firebaseAppDistribution { diff --git a/billing/src/main/java/devesh/app/billing/BillingActivity.java b/billing/src/main/java/devesh/app/billing/BillingActivity.java index a688620..628fffa 100644 --- a/billing/src/main/java/devesh/app/billing/BillingActivity.java +++ b/billing/src/main/java/devesh/app/billing/BillingActivity.java @@ -82,32 +82,56 @@ protected void onStart() { gPlayBilling.init(new BillingClientStateListener() { @Override public void onBillingServiceDisconnected() { - + Log.d(TAG, "onBillingServiceDisconnected: "); } @Override public void onBillingSetupFinished(@NonNull BillingResult billingResult) { + Log.d(TAG, "onBillingSetupFinished: getResponseCode() "+billingResult.getResponseCode()); if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { // The BillingClient is ready. You can query purchases here. - Log.d(TAG, "onBillingSetupFinished: "); + Log.d(TAG, "onBillingSetupFinished: OK"); getProducts(); fetchOwnedPlans(); + }else{ + Log.d(TAG, "onBillingSetupFinished: NOT OK"); + String errorMessage="Error"; + + if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.BILLING_UNAVAILABLE){ + errorMessage="BILLING UNAVAILABLE"; + }else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED){ + errorMessage="USER CANCELED"; + }else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.ERROR){ + errorMessage="ERROR"; + } + else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.DEVELOPER_ERROR){ + errorMessage="DEVELOPER_ERROR"; + } + Log.d(TAG, "onBillingSetupFinished: ERROR => "+errorMessage); + + Toast.makeText(BillingActivity.this, errorMessage, Toast.LENGTH_LONG).show(); + } } + + + }); - try { + /* try { getProducts(); }catch (Exception e){ - + Log.e(TAG, "onStart: ",e ); } try { - fetchOwnedPlans(); + fetchOwnedPlans(); }catch (Exception e){ - + Log.e(TAG, "onStart: ",e ); } + + */ setUIDetails(); // Check Google Play Services @@ -132,6 +156,11 @@ void getProducts(){ gPlayBilling.getProducts(new ProductDetailsResponseListener() { @Override public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List list) { + + if(list.isEmpty()){ + Log.d(TAG, "onProductDetailsResponse: EMPTY PRODUCTS "); + return; + } Log.d(TAG, "onProductDetailsResponse: "+list.get(0).toString()); productDetails=list.get(0); gPlayBilling.productDetails=productDetails; @@ -139,8 +168,9 @@ public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonN ProductDetails.SubscriptionOfferDetails s= productDetails.getSubscriptionOfferDetails().get(0); price=s.getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice(); period=s.getPricingPhases().getPricingPhaseList().get(0).getBillingPeriod(); - Log.d(TAG, "onProductDetailsResponse: SubscriptionOfferDetails "+s.toString()); - Log.d(TAG, "onProductDetailsResponse: getOfferTags "+s.getPricingPhases().getPricingPhaseList().get(0)); + + Log.d(TAG, "onProductDetailsResponse: SubscriptionOfferDetails "+s.toString()); + Log.d(TAG, "onProductDetailsResponse: getOfferTags "+s.getPricingPhases().getPricingPhaseList().get(0)); setUIDetails(); diff --git a/billing/src/main/java/devesh/app/billing/GPlayBilling.java b/billing/src/main/java/devesh/app/billing/GPlayBilling.java index c24bab1..852d752 100644 --- a/billing/src/main/java/devesh/app/billing/GPlayBilling.java +++ b/billing/src/main/java/devesh/app/billing/GPlayBilling.java @@ -26,6 +26,8 @@ import com.android.billingclient.api.QueryPurchasesParams; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; +import com.google.errorprone.annotations.Immutable; +import com.google.firebase.crashlytics.internal.model.ImmutableList; import java.util.ArrayList; import java.util.List; @@ -103,7 +105,7 @@ public GPlayBilling(Activity activity, PurchasesUpdatedListener purchasesUpdated public void init(BillingClientStateListener billingClientStateListener){ - + Log.d(TAG, "init: BillingClientStateListener"); billingClient.startConnection(billingClientStateListener); /* @@ -133,15 +135,17 @@ public void getProducts(ProductDetailsResponseListener productDetailsResponseLis Log.d(TAG, "getProducts: "); List itemsList = new ArrayList<>(); + QueryProductDetailsParams.Product qp = QueryProductDetailsParams.Product.newBuilder() .setProductId("subs") .setProductType(BillingClient.ProductType.SUBS) .build(); + itemsList.add(qp); QueryProductDetailsParams queryProductDetailsParams = QueryProductDetailsParams.newBuilder() - .setProductList(itemsList) + .setProductList(ImmutableList.from(itemsList)) .build(); billingClient.queryProductDetailsAsync( diff --git a/common/src/main/java/devesh/app/common/AdMobAPI.java b/common/src/main/java/devesh/app/common/AdMobAPI.java index e545bd6..7cc4122 100644 --- a/common/src/main/java/devesh/app/common/AdMobAPI.java +++ b/common/src/main/java/devesh/app/common/AdMobAPI.java @@ -86,7 +86,7 @@ public AdMobAPI(Activity activity) { if (!BuildConfig.DEBUG) { - List testDeviceIds = Arrays.asList("4DA615D3074C3B7ED74AF7BC445EB58B"); + List testDeviceIds = Arrays.asList("4DA615D3074C3B7ED74AF7BC445EB58B","BA7CE8A34143C5A04CCEF9F701FCADB5"); RequestConfiguration configuration = new RequestConfiguration.Builder() .setTestDeviceIds(testDeviceIds) @@ -161,6 +161,12 @@ public void onInitializationComplete(InitializationStatus initializationStatus) } public void setAdBannerTo(AdView adView) { + boolean isSub = cachePref.getBoolean(mActivity.getString(R.string.Pref_isSubscribed)); + if (isSub) { + isAdsEnabled = false; + } else { + isAdsEnabled = true; + } if (isAdsEnabled) { AdSize adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(mContext, 320); @@ -210,6 +216,12 @@ public void onAdClosed() { } public void setAdaptiveBanner(AdView adView, Activity activity) { + boolean isSub = cachePref.getBoolean(activity.getString(R.string.Pref_isSubscribed)); + if (isSub) { + isAdsEnabled = false; + } else { + isAdsEnabled = true; + } if (isAdsEnabled) { AdSize adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(mContext, 320); @@ -262,6 +274,12 @@ public void onAdClosed() { // InterstitialAd public void setAdaptiveBanner(FrameLayout adContainerView, Activity activity) { + boolean isSub = cachePref.getBoolean(activity.getString(R.string.Pref_isSubscribed)); + if (isSub) { + isAdsEnabled = false; + } else { + isAdsEnabled = true; + } if (isAdsEnabled) { AdView adView = new AdView(activity); @@ -317,6 +335,13 @@ public void onAdClosed() { public void LoadInterstitialAd(Activity activity) { mActivity = activity; + + boolean isSub = cachePref.getBoolean(mActivity.getString(R.string.Pref_isSubscribed)); + if (isSub) { + isAdsEnabled = false; + } else { + isAdsEnabled = true; + } if (isAdsEnabled) { AdRequest adRequest = new AdRequest.Builder().build(); @@ -366,6 +391,12 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { } public void ShowInterstitialAd() { + boolean isSub = cachePref.getBoolean(mActivity.getString(R.string.Pref_isSubscribed)); + if (isSub) { + isAdsEnabled = false; + } else { + isAdsEnabled = true; + } if (isAdsEnabled) { if (mInterstitialAd != null) { mInterstitialAd.show(mActivity);