所以我试图让它在奖励用户后自动关闭广告,这是我到目前为止所得到的。
请记住,我是 android studio 和 java 的新手。如果它们间隔开,则它们采用不同的方法。
private RewardedVideoAd mAd;
AdView adView;
void init_admob(){
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
mAd = MobileAds.getRewardedVideoAdInstance(this);
mAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
}
public void onRewarded(RewardItem reward) {
Toast.makeText(this, reward.getAmount()+ " " +getString(R.string.points_received), Toast.LENGTH_SHORT).show();
award(reward.getAmount(),getString(R.string.admob_credit));
exitAd();
}
public void exitAd() {
//dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); Tried But didn't work (No Errors Just didn't work)
//dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK)); Tried but didn't work (No Errors Just didn't work)
try {
LinearLayout linLay = (LinearLayout) findViewById(R.id.adView);
linLay.removeView(adView);
} catch (Exception e) {
e.printStackTrace();
}
}
linLay 错误
java.lang.ClassCastException: com.google.android.gms.ads.AdView cannot be cast to android.widget.LinearLayout
所以我真的不知道还有什么可尝试的,或者在广告获得任何帮助后如何关闭 AdView!
12345678_0001
呼如林
相关分类