在应用内购买后停用广告

时间:2016-07-03 15:38:58

标签: android

如何在应用购买后停用Admob广告?什么是最好的方式  用户重新安装应用程序?

1 个答案:

答案 0 :(得分:3)

在通常初始化admob的位置,您添加一个布尔值来检查该人是否已完成应用内购买。如果布尔值为true(购买了广告删除),则广告将永远不会显示。如果错误(未购买广告),则会显示广告。

重新安装IAB v3将获得现有购买并根据它执行操作。永久购买广告等广告不应被消费!如果是,如果您不保存布尔值或用户获得新设备,则用户必须再次购买删除广告。这会引起愤怒!

设置IAB(IAP)时,您可以查询库存。在那里inizialize一个布尔(我称之为showAds)。在onCreate中:(可以从谷歌的Trivial Drive示例获得)

 ....(other onCreate stuff. make sure setContentView is called before this:)
 Log.d(TAG, "Starting setup.");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            Log.d(TAG, "Setup finished.");

            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                complain("Problem setting up in-app billing: " + result);
                return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            mBroadcastReceiver = new IabBroadcastReceiver(Game.this);
            IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
            registerReceiver(mBroadcastReceiver, broadcastFilter);

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            Log.d(TAG, "Setup successful. Querying inventory.");
            try {
                mHelper.queryInventoryAsync(mGotInventoryListener);

            } catch (Exception e) {
                complain("Error querying inventory. Another async operation in progress.");
            }
        }
    });

    computeAds();

然后在外面:(这不是在Trivial Drive示例中)

private void computeAds(){
    AdView mAdView = (AdView) findViewById(R.id.adView);
    if(!showAds){
        mAdView.setVisibility(View.GONE);

    }else {
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }
}
购买后可以调用

computeAds即时隐藏广告。重新启动时,广告甚至不会被初始化。