横幅广告和插页式广告未合作

时间:2016-05-24 08:59:36

标签: android admob

当用户尝试打开其他活动时,我正尝试在片段和插页式广告中展示横幅广告。

横幅广告和插页式广告在我向其展示任何内容时效果非常好(例如,在没有为插页式广告编写代码时显示横幅广告,反之亦然)。

当写入两个广告的代码时,logcat中会显示以下消息。

W/GooglePlayServicesUtil: Google Play services is missing.
W/GooglePlayServicesUtil: Google Play services is missing.
W/Ads: There was a problem getting an ad response. ErrorCode: 0

play-services的问题似乎很奇怪,因为每个广告都是如上所述独立加载的。

以下是我的整个片段代码。

public class MainActivityFragment extends Fragment {

InterstitialAd mInterstitialAd;

public MainActivityFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_main, container, false);

    AdView mAdView = (AdView) root.findViewById(R.id.adView);


    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    mAdView.loadAd(adRequest);

    mInterstitialAd = new InterstitialAd(getContext());
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

    requestNewInterstitial();
    return root;
}

public void showJoke(final String joke) {

    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    } else {
        launchActivity(joke);
    }


    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
            launchActivity(joke);
        }
    });
}

public void launchActivity(String joke){

    Intent intent = new Intent(getActivity(), JokeActivity.class);
    intent.putExtra("joke", joke);
    startActivity(intent);
}
private void requestNewInterstitial() {
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();

    mInterstitialAd.loadAd(adRequest);
}

}

请帮助并分享您对可能出现的问题的看法。

0 个答案:

没有答案