如果用户支付删除横幅我想不显示它。当用户付费时我有这个功能:
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();
}
在主要活动中添加或不添加横幅:
//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);
}
}
以及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>
你知道为什么有些用户会抱怨在付费删除后仍会显示横幅吗?谢谢。
1条答案
按热度按时间sirbozc51#
最好的方法是在用户购买后删除视图。这样,你的所有观点也将重新调整。同时刷新菜单项。。。