[英]Ads stopped working after a year when app is build from newer version of Android Studio
About a year ago i finished a super simple game in android studio and published it. 大约一年前,我在android studio中完成了一个超级简单的游戏并将其发布。 Now i wanted to make a small update and show ads on more proper place.
现在,我想进行一次小更新,然后在更合适的位置展示广告。 But ads won't work at all - code is the same as it was, but ads just won't load.
但是广告根本不起作用-代码与以前相同,但是广告不会加载。
My account is not disabled since if I download my game from playstore ads still work. 我的帐户没有被禁用,因为如果我从Playstore广告下载游戏仍然可以使用。
I use different version of android studio, so the project upgraded itself, but I don't know if it changed graddle or manifest or something so this could happen. 我使用的是不同版本的android studio,因此该项目会自行升级,但我不知道它是否更改了gradle或manifest或某些内容,因此可能会发生。
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxx");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded () {
if(enableAd) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
}
});
Use onAdClosed() in your AdListener to reload your ad each time is has been displayed, and create your initial Ad as part of the mainActivity.create() . 每次显示广告时,都可以在AdListener中使用onAdClosed()重新加载广告,并在mainActivity.create()中创建您的初始广告。
Use mInterstitialAd.show() anywhere in your app when you want to show the ad. 当您想要展示广告时,请在应用中的任何位置使用mInterstitialAd.show() 。 After it is shown, it closes and will reload the next ad.
显示后,它将关闭并重新加载下一个广告。
What this does is buffers your Ad. 这是为了缓冲您的广告。 Whenever you show the interstitial ad, it shows the one that is already loaded, then reloads a new one after you've shown the ad.
每当您展示插页式广告时,它都会显示一个已经加载的插页式广告,然后在您展示广告后重新加载一个新的插页式广告。 Makes for a quicker ad.show().
使ad.show()更快。
mInterstatialAd = new InterstitialAd(getBaseContext());
mInterstatialAd.setAdUnitId(getResources()
.getString(R.string.AdmobTestInterstitial));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed () {
mInterstatialAd.loadAd(myAdRequest);
}
});
public void showMyInterstitialAd(){
if(mInterstitialAd!=null &&
mInstitialAd.isLoaded()) mInterstitialAd.show();
}
good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.