我尝试了以下代码(main_activity.java)
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
// Use an activity context to get the rewarded video instance.
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
}
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
logcat说,该广告已加载,但未显示。我想在单独的片段中显示广告,所以也许“(this)”是错误的?
谢谢您的帮助...
请参阅此参考:https://developers.google.com/admob/android/rewarded-video
最佳答案
我修好了它:
@Override
public void onRewardedVideoAdLoaded() {
mRewardedVideoAd.show();
}