在用户关闭间隙广告后,我将在我的应用程序中添加奖励广告,它将显示一个屏幕,显示之前输入的文本,并在下方有一个显示奖励广告的视频按钮(我处于测试阶段,因此我还不包括任何奖励项目,只想先显示视频广告)。
当我使用Toast小部件来识别广告是否已加载时,我意识到广告已加载(显示“onRewardedAdLoade”文本)。但是,当我单击观看视频按钮时,似乎没有调用show RewardedVideo()。有人能帮我看看我的代码有什么问题吗?
我的代码:
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.mysecondapp.MESSAGE";
private AdView mAdView;
private InterstitialAd mInterstitialAd;
Button mMyButton;
private RewardedAd rewardedAd;
private Button showVideoButton;
boolean isLoading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
loadRewardedAd();
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mMyButton = (Button) findViewById(R.id.button);
mMyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
sendMessage(mAdView);
// Create the "show" button, which shows a rewarded video if one is loaded.
showVideoButton = findViewById(R.id.show_video_button);
showVideoButton.setVisibility(View.INVISIBLE);
showVideoButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
showRewardedVideo();
}
});
}
});
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
}
private void loadRewardedAd() {
if (rewardedAd == null || !rewardedAd.isLoaded()) {
rewardedAd = new RewardedAd(this, "ca-app-pub-3940256099942544/5224354917");
isLoading = true;
rewardedAd.loadAd(
new AdRequest.Builder().build(),
new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
MainActivity.this.isLoading = false;
Toast.makeText(MainActivity.this, "onRewardedAdLoaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
MainActivity.this.isLoading = false;
Toast.makeText(MainActivity.this, "onRewardedAdFailedToLoad", Toast.LENGTH_SHORT)
.show();
}
});
}
}
/**
* Called when the user taps the Send button
*/
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
private void showRewardedVideo() {
showVideoButton.setVisibility(View.INVISIBLE);
if (rewardedAd.isLoaded()) {
RewardedAdCallback adCallback =
new RewardedAdCallback() {
@Override
public void onRewardedAdOpened() {
// Ad opened.
Toast.makeText(MainActivity.this, "onRewardedAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedAdClosed() {
// Ad closed.
Toast.makeText(MainActivity.this, "onRewardedAdClosed", Toast.LENGTH_SHORT).show();
// Preload the next video ad.
MainActivity.this.loadRewardedAd();
}
@Override
public void onUserEarnedReward(RewardItem rewardItem) {
// User earned reward.
Toast.makeText(MainActivity.this, "onUserEarnedReward", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedAdFailedToShow(int errorCode) {
// Ad failed to display
Toast.makeText(MainActivity.this, "onRewardedAdFailedToShow", Toast.LENGTH_SHORT)
.show();
}
};
rewardedAd.show(this, adCallback);
}
}
}
谢啦!
像这样修改您的奖励广告加载方法
private void loadRewardedAd() {
if (rewardedAd == null || !rewardedAd.isLoaded()) {
isLoading = true;
rewardedAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
}
}
*****Method ends here***** //implement RewardedVideoAdListners' callback methods like this
@Override
public void onRewarded(RewardItem reward) {
Toast.makeText(this, "onRewarded! currency: " + reward.getType() + " amount: " +
reward.getAmount(), Toast.LENGTH_SHORT).show();
// Reward the user.
}
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdClosed() {
MainActivity.this.loadRewardedAd();
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoCompleted() {
Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
}
然后像这样实现RewardedVideoAdListener
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
显示ads方法,如下所示
private void showRewardedVideo() {
showVideoButton.setVisibility(View.INVISIBLE);
if(rewardedAd.isLoaded){
rewarded.show();
} else {
//Do something...
}
}
我正在尝试使用AdMob显示奖励视频广告。我添加了2个广告网络(AdColony、InMobi)并提供了所有必需的详细信息,如帐户ID等。 我还下载并编译了所需的网络SDK和适配器。 广告代码: 问题是我总是从AdMob那里得到同样的回应: 获取广告回复时出现问题。错误代码:0 有什么办法解决这个问题吗? 更新: 我通过从AdRequest中删除“addTestDevice()”克服了加载广告的问
当尝试加载奖励广告时,我遇到以下错误: <代码> 加载测试广告有效,但当尝试显示真实广告时,它会说:请求错误:没有广告要显示。 苹果不会允许我的应用出现在应用商店中,因为广告不起作用。 我还没有设法解决这个问题,因为这篇文章没有帮助。 另外,我还没有在我的代码中使用这个:<代码>。addTestDevice()和我的Admob帐户已经超过24小时了(可能已经有很多年了)。 有办法解决这个问题吗?
我正在尝试使用Admob在我的android应用程序中显示奖励视频广告。如果我用谷歌示例广告单元ID运行应用程序,它工作得很好,但如果我将其更改为我的奖励广告单元ID,则不会加载广告。
我在Unity3d中显示admob插件的奖励视频广告时遇到问题。首先,这是我的脚本: 我用一个按钮运行RequestRewardVideo()方法,但什么也没发生。我尝试运行按钮中的和中的方法,但只显示了视频1/3次。。。这个怎么了? 提前感谢
看到正在发生的问题:用户可以观看获奖广告以解锁应用程序中的高级功能。事实证明,已经观看了几个获奖视频,用户正在赚取高级功能,但在AdMob面板上,奖励视频总是显示为0.00美元,它是唯一一个似乎从未获胜的广告单元。当月有87次展示,收入为0.00美元。目前正在为用户加载,未配置为testDevice。 注意:我没有使用最新版本的admob sdk,因为当我将依赖项放在最新版本上时,其他依赖项存在一