我正在寻找一种在我的 Android 应用中预加载 RevMob 横幅和插页式广告的方法?广告目前可能需要 5 到 30 秒,这对于应用程序类型来说太长了。
任何帮助表示赞赏。
如果您使用广告对象,您可以进行预加载(RevMob API Docs)并显示如下:
Fullscreen fullscreen = revmob.createFullscreen(this);
if (fullscreen.isAdLoaded()) {
fullscreen.show();
}
但该节目只有在广告已加载的情况下才有效!
添加到 AndrodMainfest.xml 文件
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity
android:name="com.revmob.ads.fullscreen.FullscreenActivity"
android:configChanges="keyboardHidden|orientation" >
</activity>
// 私有 RevMobFullscreen 全屏;
private static final String REVMOB_APP_ID = "rebmob_id";
private RevMob revmob;
RevMobAdsListener revmobListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
onStart();
// Starting RevMob session
revmob = RevMob.start(this, REVMOB_APP_ID);
revmob.printEnvironmentInformation(this);
revmob.setTestingMode(RevMobTestingMode.WITH_ADS); // with this line,
// RevMob will
// always deliver a
// sample ad
// revmob.setTestingMode(RevMobTestingMode.WITHOUT_ADS);
// revmob.createFullscreen(this, revmobListener);
//
revmob.showFullscreen(this);
revmob.setTimeoutInSeconds(5);
}
方法调用
public void onStart() {
super.onStart();
revmobListener = new RevMobAdsListener() {
@Override
public void onRevMobAdDisplayed() {
Log.i("[RevMob]", "onAdDisplayed");
}
@Override
public void onRevMobAdReceived() {
Log.i("[RevMob]", "onAdReceived");
}
@Override
public void onRevMobAdNotReceived(String message) {
Log.i("[RevMob]", "onAdNotReceived");
}
@Override
public void onRevMobAdDismiss() {
Log.i("[RevMob]", "onAdDismiss");
}
@Override
public void onRevMobAdClicked() {
Log.i("[RevMob]", "onAdClicked");
}
};
}
public void showFullscreen(View view) {
RevMobFullscreen fs = revmob.createFullscreen(this, revmobListener);
fs.show();
}
public void revMobOpenPopup(View view) {
// revmob.showPopup(this);
RevMobPopup popup = revmob.createPopup(this, revmobListener);
popup.show();
}
在最新版本中,有一些重要的变化。只有在实施某些中介策略时,您才必须使用“isAdLoaded”。否则,您可以直接使用“显示”和“隐藏”方法。
RevMob revmob = RevMob.start(this, APPLICATION_ID);
RevMobFullscreen fullscreen = revmob.createFullscreen(this);
// it will show the ad. If it is not loaded yet, it will show it after it is completely loaded automatically.
fullscreen.show();
// If you change your scene and you do not want to show the ad anymore, you can call this method:
fullscreen.hide();