我正在尝试通过 AdMob 将 Chartboost 和 AdMob 插页式广告集成到我的游戏中。我还希望集成 Chartboost 应用墙和分析。为了使应用程序墙和分析能够正常工作,我需要 AdMob 的自定义事件侦听器类之外的 CB 对象。
目前,我的听众活动看起来像这样。
public class ChartboostAdAdapter implements CustomEventInterstitial{
private Chartboost cb;
protected static CustomEventInterstitialListener mListener;
Activity activity;
@Override
public void destroy() {
cb.onDestroy(activity);
}
@Override
public void requestInterstitialAd(CustomEventInterstitialListener customListener, Activity activity,
String param1, String param2, MediationAdRequest mAdRequest, Object object) {
mListener = customListener;
this.activity = activity;
cb = Chartboost.sharedChartboost();
cb.cacheInterstitial("Post Game");
}
@Override
public void showInterstitial() {
cb.showInterstitial();
}
}
我的 Chartboost 委托在单独的文件中定义。将 CustmEventInterstitialListener 声明为静态允许我从 CB 委托访问它。虽然设置有效,但由于 CustomEventInterstitialListener 被声明为静态,我担心内存泄漏。
我对如何使用 Chartboost 应用程序墙以及在调解横幅时进行分析一无所知。我能想到的唯一选择是在应用程序中使用硬编码中介,并通过 AdMob 牺牲动态重新排序。没有更好的办法吗?
更新:有关我为什么需要访问CustomEventInterstitialListener
. 我需要调用AdMob 中介范围之外的方法,例如cb.cacheMoreApps()
和。cb.getAnalytics().trackEvent("Stats")
此外,我需要对 didCacheMoreApps 采取行动,以便为More Apps/App-wall创建自定义瀑布,我必须在CustomEventInterstitial
类外定义 Delegate。
根据要求,这里是 CBDelegate 的代码:
private ChartboostDelegate cbdelegate = new ChartboostDelegate() {
final String tag = "CHARTBOOST";
@Override
public boolean shouldRequestMoreApps() {
return true;
}
@Override
public boolean shouldRequestInterstitialsInFirstSession() {
return true;
}
@Override
public boolean shouldRequestInterstitial(String arg0) {
return true;
}
@Override
public boolean shouldDisplayMoreApps() {
return true;
}
@Override
public boolean shouldDisplayLoadingViewForMoreApps() {
return true;
}
@Override
public boolean shouldDisplayInterstitial(String arg0) {
return true;
}
@Override
public void didShowMoreApps() {
}
@Override
public void didShowInterstitial(String arg0) {
if(mAdAdapter !=null) mAdAdapter.mListener.onPresentScreen();
}
@Override
public void didFailToLoadMoreApps() {
Log.i(tag, "Interstital failed to load more interstital");
// Waterfall code for More-App/App-wall. Use Ad-Mob Custom event to manage it?
}
@Override
public void didFailToLoadInterstitial(String arg0) {
if(mAdAdapter !=null) mAdAdapter.mListener.onFailedToReceiveAd();
Log.i(tag, "Interstital failed to load");
}
@Override
public void didDismissMoreApps() {
Log.i(tag, "More apps dismissed");
finish();
}
@Override
public void didDismissInterstitial(String arg0) {
if(mAdAdapter !=null) mAdAdapter.mListener.onDismissScreen();
Log.i(tag, "Interstital dismissed");
}
@Override
public void didCloseMoreApps() {
Log.i(tag, "More appds closed");
finish();
}
@Override
public void didCloseInterstitial(String arg0) {
Log.i(tag, "Interstital closed");
if(mAdAdapter !=null) mAdAdapter.mListener.onDismissScreen();
}
@Override
public void didClickInterstitial(String arg0) {
}
@Override
public void didCacheMoreApps() {
Log.i(tag, "More apps cached");
}
@Override
public void didCacheInterstitial(String arg0) {
Log.i(tag, "Interstital cached");
if(mAdAdapter !=null) mAdAdapter.mListener.onReceivedAd();
}
@Override
public void didFailToLoadUrl(String arg0) {
Log.i(tag, "Interstital failed to load url");
if(mAdAdapter !=null) mAdAdapter.mListener.onFailedToReceiveAd();
}
@Override
public void didClickMoreApps() {
}
};