我正在使用WebView,并且已完成所有设置。如果用户访问名为X的网站,则会显示广告。如果用户关闭广告而不跟踪它,我希望WebView页面返回上一步。我怎样才能做到这一点?我曾考虑过将其添加到onRewardedVideoAdClosed()端,但视频播放成功的用户也向后退。
@Override
public void onRewardedVideoAdClosed() {
Toast.makeText(getActivity(), "Reklam sayfası kapatıldı.", Toast.LENGTH_SHORT).show();
loadRewardedVideoAd();
webView.goBack(); //doesn't work
}
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem reward) {
Toast.makeText(getActivity(), "Başarılı! İçerik görüntüleme hakkı kazandınız. " ,/*+ reward.getType() + " amount: " + reward.getAmount(),*/ Toast.LENGTH_SHORT).show();
// Reward the user.
}
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(getActivity(), "onRewardedVideoAdLeftApplication", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdClosed() {
Toast.makeText(getActivity(), "Reklam sayfası kapatıldı.", Toast.LENGTH_SHORT).show();
loadRewardedVideoAd();
}
@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(getActivity(), "Reklam yükelmesi başarısız oldu.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(getActivity(), "Geçiş reklamları hazır.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(getActivity(), "Geçiş reklamı açıldı.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(getActivity(), "Geçiş reklamı başladı.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoCompleted() {
Toast.makeText(getActivity(), "Reklam bitti.", Toast.LENGTH_SHORT).show();
}
@Override
public void onResume() {
mRewardedVideoAd.resume(getActivity());
super.onResume();
}
@Override
public void onPause() {
mRewardedVideoAd.pause(getActivity());
super.onPause();
}
@Override
public void onDestroy() {
mRewardedVideoAd.destroy(getActivity());
super.onDestroy();
}
答案 0 :(得分:0)
您可以简单地记住,如果用户获得了奖励。以下代码基于新的API,但是使用旧的API来实现此想法应该很简单。
RewardedAdCallback adCallback = new RewardedAdCallback() {
boolean rewardEarned = false;
@Override
public void onRewardedAdOpened() {
// Ad opened.
}
@Override
public void onRewardedAdClosed() {
loadAd();
showResponse(rewardEarned ? R.string.rewardEarned : R.string.adAborted);
}
@Override
public void onUserEarnedReward(@NonNull RewardItem reward) {
rewardEarned = true;
}
@Override
public void onRewardedAdFailedToShow(int errorCode) {
// Ad failed to display
}
};