横幅继续出现后,用户付费删除?共享首选项java

qyuhtwio  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(414)

如果用户支付删除横幅我想不显示它。当用户付费时我有这个功能:

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>

你知道为什么有些用户会抱怨在付费删除后仍会显示横幅吗?谢谢。

sirbozc5

sirbozc51#

最好的方法是在用户购买后删除视图。这样,你的所有观点也将重新调整。同时刷新菜单项。。。

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();

    }

相关问题