2016-07-03 89 views

回答

2

在哪里你通常会初始化admob,你添加一个布尔值来检查天气或没有人做了应用内购买。如果布尔值为真(购买广告删除),广告将永远不会显示。如果它是假的(不购买广告去除),它会显示广告。

在重新安装IAB v3时将获得现有购买并基于此购物。永久购买,如删除广告不应该消费!如果这是用户将不得不再次购买删除广告,如果你不保存布尔或用户得到一个新的设备。这会引起愤怒!

设置IAB(IAP)时,查询库存。在那里初始化一个布尔值(我称之为showAds)。在的onCreate:

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

话外(也可以从谷歌琐碎的驱动例子得到):(这是不是在琐碎驱动器为例)

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可以在购买后调用这会立即隐藏广告。重新启动时,广告甚至不会被初始化。

+0

,谢谢,我使用的共享prefernce保存布尔值。 – Mubashshir

1

这是购买后删除广告的最佳方式

if (!bp.isPurchased("prime") { 
 
      mAdView = (AdView) findViewById(R.id.adView1); 
 
      AdRequest adRequest = new AdRequest.Builder().build(); 
 
      mAdView.loadAd(adRequest); 
 

 

 
     }else if(bp.isPurchased("prime")){ 
 
      mAdView = (AdView) findViewById(R.id.adView1); 
 

 
      mAdView.setVisibility(View.GONE); 
 

 
     }

我使用https://github.com/anjlab/android-inapp-billing-v3