无法为我的Android应用显示来自Smaato Ads的视频广告

时间:2018-12-24 08:21:59

标签: android ads smaato

我正在尝试在Android应用上实施Smaato视频广告。      我已按照Smaato页面和Smaato示例应用程序中的说明进行操作,但是,我无法显示Smaato视频广告。      显然应该全屏显示视频广告的代码是:

private static Video smaatoVideoAd; // A Smaato Video global variable

smaatoVideoAd = new Video(this.getApplicationContext());
smaatoVideoAd.getAdSettings().setPublisherId(0); //int of 0 is supposedly a test mode
//smaatoVideoAd.getAdSettings().setPublisherId(PublisherID);
smaatoVideoAd.getAdSettings().setAdspaceId(0);  //int of 0 is supposedly a test mode
//smaatoVideoAd.getAdSettings().setAdspaceId(VideoAd_ID);
smaatoVideoAd.setVastAdListener(this);
smaatoVideoAd.setAutoCloseDuration(5);
smaatoVideoAd.disableAutoClose(true);
smaatoVideoAd.setVideoSkipInterval(3);
} // End of onCreate

// Called when the video has been loaded.
@Override
public void onReadyToShow() {
    // Call this when you want to show the video ad.
    smaatoVideoAd.show();
}

@Override
    public void onWillShow() {
    // Called when the ad will show.
}

@Override
public void onWillOpenLandingPage() {
    // Called when the banner has been clicked.
}

@Override
public void onWillClose() {
    // Called when Interstitial ad will be closed.
}

@Override
public void onFailedToLoadAd() {
    // called when video failed to load.
}

用于build.gradle的Smaato库已经设置好了,这非常简单且简短:

 repositories {
 ...
     flatDir {
         dirs 'libs'
     }
 ...
 }

 dependencies {
 ...
     implementation name:'SOMAAndroid-9.1.3-release', ext:'aar'
 ...
 }

并在AndroidManifest.xml中:

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <uses-feature android:name="android.hardware.location.gps" />
 <uses-feature android:name="android.hardware.location.network" />

 <meta-data android:name=”com.google.android.gms.version” android:value=”@integer/google_play_services_version”/>
 <activity android:name="com.smaato.soma.interstitial.InterstitialActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />
 <activity android:name="com.smaato.soma.video.VASTAdActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />
 <activity android:name="com.smaato.soma.ExpandedBannerActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />

此外,Smaato声明:“ 自v8.0.0起,Smaato Android SDK包含自动初始化例程。因此,发布者无需手动调用其他SDK初始化方法。” < / p>

但是运行此代码,会在Logcat中给我以下警报:

SOMA_VIDEO:必须先加载视频,然后再显示

因此,视频添加根本不会加载。我在这里想念什么? 你能帮助我吗?谢谢。

1 个答案:

答案 0 :(得分:0)

解决了!显然,我的顺序顺序不正确。按照此顺序,Logcat中的警告消失:

    smaatoVideoAd = new Video(this.getApplicationContext());
    smaatoVideoAd.setVastAdListener(this);
    smaatoVideoAd.setAutoCloseDuration(3);
    smaatoVideoAd.disableAutoClose(false);
    smaatoVideoAd.setVideoSkipInterval(1);

    smaatoVideoAd.getAdSettings().setPublisherId(0); // Trial Publisher Id: 0
    smaatoVideoAd.getAdSettings().setAdspaceId(3090); // Trial Adspace Id for video: 3090
    smaatoVideoAd.asyncLoadNewBanner();

请注意,试用模式下Smaato视频广告的代码为3090,而不是0。此外,我已将Smaato广告置于新的活动中,因此关闭广告将关闭子活动,而不是我的主要活动。