0

我正在尝试在我的 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 初始化方法”。

但是运行这段代码,在 Logcat 中给了我以下警报:

SOMA_VIDEO:视频必须在显示之前加载

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

4

1 回答 1

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 广告放入新活动中,因此关闭广告将关闭子活动,而不是我的主要活动。

于 2019-01-11T20:24:13.193 回答