Adapter 中的奖励视频广告版本 20.0.0 以上
Rewarded Video Ads version 20.0.0 above in Adapter
我是 Java 的新手,我想在 Adapter.class 中实施奖励视频广告 20.0.0 或更高版本。正如我在 link 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 的每个列表中实施奖励视频广告
我从这个 link 中找到了完整的教程。作为 DarShan 的回答,我必须调整有效 activity 上下文的代码。一切运行良好。这是教程中的代码。我将 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.");
}
我是 Java 的新手,我想在 Adapter.class 中实施奖励视频广告 20.0.0 或更高版本。正如我在 link 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 的每个列表中实施奖励视频广告
我从这个 link 中找到了完整的教程。作为 DarShan 的回答,我必须调整有效 activity 上下文的代码。一切运行良好。这是教程中的代码。我将 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.");
}