我将在本月晚些时候在我的应用程序中运行一个comp,我想使用广告。我想要做的是当会员点击按钮显示广告时,如果他们点击广告打开Google Play,则会显示促销代码。我正在使用Ad Mob提供的股票代码来填充插页式广告。只是想知道如何编辑以便在点击广告后显示促销代码。
public class comp extends AppCompatActivity {
private InterstitialAd mInterstitialAd;
private TextView Pcode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comp);
Pcode = (TextView) findViewById(R.id.PromoCode);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.fullscreen_ad_unit_id));
Button bce = (Button) findViewById(R.id.bcompenter);
bce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showInterstitial();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
StartTask();
}
});
}
});
}
private void showInterstitial() {
// Show the ad if it's ready. Otherwise toast and restart the game.
if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Toast.makeText(this, "Thanks for installing using H20 Droid Apps", Toast.LENGTH_SHORT).show();
StartTask();
}
}
private void StartTask() {
// Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
Pcode.setVisibility(View.VISIBLE);
}
}
}