我正试图在我的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声明:“自8.0.0以来,Smaato Android SDK包含一个自动初始化例程,因此不需要发布者手动调用附加的SDK初始化方法”。
但是,运行此代码,将在Logcat中给出以下警告:
SOMA_VIDEO:视频必须在显示之前加载
因此,视频添加根本没有加载。我在这里错过了什么?你能帮帮我吗?谢谢。
发布于 2019-01-11 20:24:13
解决了!显然,我没有得到正确的顺序。使用此命令,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广告在一个新的活动,所以关闭广告将关闭儿童活动,而不是我的主要活动。
https://stackoverflow.com/questions/53910925
复制相似问题