Reputation: 4253
If user pay to remove banners I'd like to not show it. I have this function when user pay:
void savepremium() {
SharedPreferences pref = getApplicationContext().getSharedPreferences("pref01", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putString("plus", "2");
editor.apply();
String string = "Thanks";
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
And this to add or not banners in main activity:
//admob
SharedPreferences pref = getApplicationContext().getSharedPreferences("pref01", MODE_PRIVATE);
String plus = pref.getString("plus", "1");
assert plus != null;
if(plus.equals("1")) {
AdView adView = new AdView(MainActivity.this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-xxx");
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
else {
AdView mAdView = findViewById(R.id.adView);
if (mAdView.getVisibility() == View.VISIBLE) {
mAdView.setVisibility(View.GONE);
}
}
and the xml:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-xxx/xxx">
</com.google.android.gms.ads.AdView>
Any ideas why some users are complaining about banners showing even after they pay to remove? Thanks a lot.
Upvotes: 0
Views: 52
Reputation: 2448
Best way is to remove the view once user purchases. This way all your views will be realign as well. Refresh your menu items as well...
if (getIsLicense() || BuildConfig.IsTestingON) {
RemoveView();
}
private void RemoveView() {
Log.d(TAG, "InsideRemoveView");
if (adView != null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.linearlayout);
layout.removeView(adView);
}
if (Build.VERSION.SDK_INT >= 11)
this.invalidateOptionsMenu();
else
supportInvalidateOptionsMenu();
}
Upvotes: 1