【问题标题】:Rewarded Video Ads version 20.0.0 above in Adapter适配器中的激励视频广告版本 20.0.0 以上
【发布时间】:2022-01-21 17:47:58
【问题描述】:

我是 Java 新手,我想在 Adapter.class 中实现奖励视频广告 20.0.0 或更高版本。正如我在此链接https://developers.google.com/admob/android/rewarded 中阅读的那样,一切运行良好,直到我找到显示奖励广告的代码。如果在 MainActivity.class 中,代码如下所示

if (mRewardedAd != null) {
  Activity activityContext = MainActivity.this;
  mRewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
    @Override
    public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
      // Handle the reward.
      Log.d(TAG, "The user earned the reward.");
      int rewardAmount = rewardItem.getAmount();
      String rewardType = rewardItem.getType();
    }
  });
} else {
  Log.d(TAG, "The rewarded ad wasn't ready yet.");
}

我的问题是,如何在Adapter.class中实现上面的代码?

感谢您的回答。这对我有很大帮助。

编辑:为了让问题更清楚,我想在 RecyclerView 的每个列表中实施奖励视频广告

【问题讨论】:

  • 您可以按原样使用它,您唯一需要的是一个有效的活动上下文,您可以通过构造函数将其传递给适配器。例如:new MyAdapter adapter = MyAdapter(MainActivity.this);
  • 我从这个视频youtube.com/watch?v=Rcfpejad3PQ&list=WL中找到了一个教程。作为您的答案,我必须编写有效的活动上下文。谢谢@DarShan。

标签: java android android-studio admob-rewardedvideoad rewardedvideoad


【解决方案1】:

我从link 中找到了完整的教程。作为 DarShan 的回答,我必须调整有效活动上下文的代码。一切运行良好。这是我在教程中的代码。我将MainActivity.this 更改为有效的activity

if (mRewardedAd != null) {
  Activity activityContext = activity;
  mRewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
    @Override
    public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
      // Handle the reward.
      Log.d(TAG, "The user earned the reward.");
      int rewardAmount = rewardItem.getAmount();
      String rewardType = rewardItem.getType();
    }
  });
} else {
  Log.d(TAG, "The rewarded ad wasn't ready yet.");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    相关资源
    最近更新 更多