@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Locate the NativeExpressAdView. mAdView = findViewById(R.id.adView); // Set its video options. mAdView.setVideoOptions(new VideoOptions.Builder() .setStartMuted(true) .build()); // The VideoController can be used to get lifecycle events and info about an ad's video // asset. One will always be returned by getVideoController, even if the ad has no video // asset. mVideoController = mAdView.getVideoController(); mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() { @Override public void onVideoEnd() { Log.d(LOG_TAG, "Video playback is finished."); super.onVideoEnd(); } }); // Set an AdListener for the AdView, so the Activity can take action when an ad has finished // loading. mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { if (mVideoController.hasVideoContent()) { Log.d(LOG_TAG, "Received an ad that contains a video asset."); } else { Log.d(LOG_TAG, "Received an ad that does not contain a video asset."); } } }); mAdView.loadAd(new AdRequest.Builder().build()); }
private void initData() { //初始化firebase 统计 FirebaseAnalytics.getInstance(getApplicationContext()); //创建广告请求 adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)//所有的模拟器 .addTestDevice("74BAABC1A0E77EB8C34896404447DBEC")//nexus 5 .addTestDevice("E3A8BB93EE8D9CF7C0B5351AB456C4C5")//我的锤子M1L .build(); //横幅广告 adv_banner.loadAd(adRequest); //插页广告 interstitialAd = new InterstitialAd(this); interstitialAd.setAdUnitId(getString(R.string.insert_ad_unit_id));//设置单元id //增加监听 interstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { //关闭了这个广告先加载下一个广告 requestNewInterstitial(); } }); //加载插页广告 requestNewInterstitial(); neadv_native.setAdListener(new AdListener() { @Override public void onAdFailedToLoad(int i) { Log.d("AdListener", "onAdFailedToLoad i:" + i); super.onAdFailedToLoad(i); } }); // Set its video options. neadv_native.setVideoOptions(new VideoOptions.Builder() .setStartMuted(true) .build()); // The VideoController can be used to get lifecycle events and info about an ad's video // asset. One will always be returned by getVideoController, even if the ad has no video // asset. mVideoController = neadv_native.getVideoController(); mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() { @Override public void onVideoEnd() { Log.d("onVideoEnd", "Video playback is finished."); super.onVideoEnd(); } }); // Set an AdListener for the AdView, so the Activity can take action when an ad has finished // loading. neadv_native.setAdListener(new AdListener() { @Override public void onAdLoaded() { if (mVideoController.hasVideoContent()) { Log.d("onAdLoaded", "Received an ad that contains a video asset."); } else { Log.d("onAdLoaded", "Received an ad that does not contain a video asset."); } } }); //加载原生广告 neadv_native.loadAd(new AdRequest.Builder().build()); }
public VideoOptions getVideoOptions() { return videoOptions; }
public void setVideoOptions(VideoOptions videoOptions) { this.videoOptions = videoOptions; }