简体   繁体   English

使用较新版本的Android Studio构建应用后,一年后广告停止工作

[英]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.

相关问题 约束在较新版本的 android studio 中无法正常工作 - Constraints not working properly in a newer version of android studio 应用停止运行Android Studio - App stopped working Android Studio 横幅广告不适用于 Android Studio。 放置横幅广告后应用程序崩溃 - Banner ads not working for Android studio. App crashing after placing banner ad Spring 启动应用程序在从 2.37 版本迁移到 2.4.1 版本后停止工作,它在 windows 上工作,但在 linux 机器上不工作 - Spring boot app stopped working after migration from 2.37 to 2.4.1 version, it is working on windows but not on linux machine 从Android Studio启动的应用程序停止工作 - Launch app from Android Studio stopped to work Android Studio-应用已停止 - Android studio - app stopped 已加载“旧” Android Studio项目-Studio更新后,它将不再打开/编译,要求更新版本吗? - Loaded “old” Android Studio project - after Studio updates it will no longer open/compile asking for even newer version? Android Wear应用程式已停止在Android Studio模拟器中运作 - Android Wear app has stopped working in android studio emulator 触摸插页式广告时,应用程序“不幸停止” - app “unfortunately stopped” when touching interstitial ads Android App停止工作 - Android App Stopped working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM