@Override public void initialize(Context context, MediationAdRequest adRequest, String unused, MediationRewardedVideoAdListener listener, Bundle serverParameters, Bundle networkExtras) { try { AdapterParametersParser.Config config = AdapterParametersParser.parse(networkExtras, serverParameters); mMediationRewardedVideoAdListener = listener; mVungleManager = VungleManager.getInstance(config.getAppId(), config.getAllPlacements()); mVungleManager.addListener(mId, mVungleListener); if (mVungleManager.isInitialized()) { mInitialized = true; mMediationRewardedVideoAdListener.onInitializationSucceeded(VungleAdapter.this); } else { mVungleListener.setWaitingInit(true); mVungleManager.init(context); } } catch (IllegalArgumentException e) { if (listener != null) { listener.onInitializationFailed(VungleAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } } }
/*************** * MediationRewardedVideoAdapter methods ***************/ @Override public void initialize(Context context, MediationAdRequest mediationAdRequest, String userId, MediationRewardedVideoAdListener mediationRewardedVideoAdListener, Bundle serverParams, Bundle networkExtras) { this._mediationRewardedVideoAdListener = mediationRewardedVideoAdListener; _adColonyRewardedInterstitialListener = new AdColonyAdListener(this, mediationRewardedVideoAdListener); boolean success = AdColonyManager.getInstance() .configureAdColony(context, serverParams, mediationAdRequest, networkExtras); if (success) { AdColonyManager.getInstance().rewardedAdsConfigured = true; this._mediationRewardedVideoAdListener.onInitializationSucceeded(this); } else { this._mediationRewardedVideoAdListener .onInitializationFailed(this, AdRequest.ERROR_CODE_INVALID_REQUEST); } }
@Override public void initialize(Context context, MediationAdRequest adRequest, String unused, MediationRewardedVideoAdListener adListener, Bundle serverParameters, Bundle mediationExtras) { if (!(context instanceof Activity)) { Log.e(TAG, "Requires an Activity context to initialize!"); adListener.onInitializationFailed( NendRewardedAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } Activity activity = (Activity) context; mRewardedVideoEventForwarder = new NendMediationRewardedVideoEventForwarder(activity, NendRewardedAdapter.this, serverParameters, adListener); if (isInitialized()) { adListener.onInitializationSucceeded(this); } else { adListener.onInitializationFailed(this, AdRequest.ERROR_CODE_INTERNAL_ERROR); } }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener mediationInterstitialListener, Bundle bundle, MediationAdRequest mediationAdRequest, Bundle bundle1) { String adunit = bundle.getString(MOPUB_AD_UNIT_KEY); mMoPubInterstitial = new MoPubInterstitial((Activity) context, adunit); mMoPubInterstitial.setInterstitialAdListener( new mMediationInterstitialListener(mediationInterstitialListener)); //If test mode is enabled if (mediationAdRequest.isTesting()) { mMoPubInterstitial.setTesting(true); } mMoPubInterstitial.setKeywords(getKeywords(mediationAdRequest)); mMoPubInterstitial.load(); }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener listener, Bundle serverParameters, MediationAdRequest adRequest, Bundle mediationExtras) { mInterstitialListener = listener; if (!isValidRequestParameters(context, serverParameters)) { mInterstitialListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } String placementId = serverParameters.getString(PLACEMENT_PARAMETER); mInterstitialAd = new InterstitialAd(context, placementId); mInterstitialAd.setAdListener(new InterstitialListener()); buildAdRequest(adRequest); mInterstitialAd.loadAd(); }
@Override public void initialize(Context context, MediationAdRequest mediationAdRequest, String unused, MediationRewardedVideoAdListener mediationRewardedVideoAdListener, Bundle serverParameters, Bundle networkExtras) { mRewardedListener = mediationRewardedVideoAdListener; if (!isValidRequestParameters(context, serverParameters)) { mRewardedListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } String placementId = serverParameters.getString(PLACEMENT_PARAMETER); mRewardedVideoAd = new RewardedVideoAd(context, placementId); mRewardedVideoAd.setAdListener(new RewardedVideoListener()); mIsInitialized = true; mRewardedListener.onInitializationSucceeded(this); }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle networkExtras) { if (mRewardedVideoAd == null) { Log.w(TAG, "Failed to request rewarded video ad, adapter has not been initialized."); mIsInitialized = false; if (mRewardedListener != null) { mRewardedListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INTERNAL_ERROR); } } else { if (mRewardedVideoAd.isAdLoaded()) { mRewardedListener.onAdLoaded(this); } else { buildAdRequest(mediationAdRequest); mRewardedVideoAd.loadAd(true); } } }
@Override public void initialize(Context context, MediationAdRequest adRequest, String userId, MediationRewardedVideoAdListener listener, Bundle serverParameters, Bundle networkExtras) { if (!(context instanceof Activity)) { listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } MaioAds.setAdTestMode(adRequest.isTesting()); this.mMediationRewardedVideoAdListener = listener; mIsRewardedVideoInitialized = true; loadServerParameters(serverParameters); if (!isInitialized()) { //maio sdk initialization MaioEventForwarder.initialize((Activity) context, this.mMediaId); } }
@Override //Load the next maio rewarded video ad public void loadAd(MediationAdRequest adRequest, Bundle serverParameters, Bundle networkExtras) { if (!isInitialized()) return; //Load new server parameters in case zone id has changed loadServerParameters(serverParameters); if (MaioAds.canShow(this.mRewardVideoZoneId)) { if (this.mMediationRewardedVideoAdListener != null) { this.mMediationRewardedVideoAdListener.onAdLoaded(Rewarded.this); } } else { if (this.mMediationRewardedVideoAdListener != null) { this.mMediationRewardedVideoAdListener .onAdFailedToLoad(Rewarded.this, AdRequest.ERROR_CODE_NO_FILL); } } }
/** * Returns a SASAdPlacement instance from passed parameters */ public static SASAdPlacement getPlacementFromString(String placementString, MediationAdRequest adRequest) { SASAdPlacement adPlacement = new SASAdPlacement(); // tokenize placement string and fill adPlacement; String[] ids = placementString.split("/"); if (ids.length >= 3) { try { adPlacement.siteId = Integer.parseInt(ids[0].trim()); adPlacement.pageId = ids[1].trim(); adPlacement.formatId = Integer.parseInt(ids[2].trim()); } catch (Exception e) { // invalid placement, return null return null; } } // extract keywords and concatenate them using semicolon as separator Set<String> keywordSet = adRequest.getKeywords(); if (keywordSet != null) { for (String keyword: keywordSet) { if (adPlacement.targeting.length() > 0) { keyword = ";".concat(keyword); } adPlacement.targeting = adPlacement.targeting.concat(keyword); } } return adPlacement; }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle bundle, Bundle bundle1) { if (interstitial != null) { interstitial.load(); } }
private void load(CustomEventBannerListener customEventBannerListener, MediationAdRequest mediationAdRequest, int slotId, int adSize, Context context) { bannerListener = customEventBannerListener; if (myTargetView == null) { myTargetView = new MyTargetView(context); myTargetView.init(slotId, adSize, false); if (mediationAdRequest != null) { myTargetView.getCustomParams().setGender(mediationAdRequest.getGender()); Date date = mediationAdRequest.getBirthday(); if (date != null && date.getTime() != -1) { GregorianCalendar calendar = new GregorianCalendar(); GregorianCalendar calendarNow = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); int a = calendarNow.get(GregorianCalendar.YEAR) - calendar.get(GregorianCalendar.YEAR); if (a >= 0) { myTargetView.getCustomParams().setAge(a); } } } myTargetView.getCustomParams().setCustomParam("mediation", "1"); myTargetView.setListener(myTargetViewListener); } myTargetView.load(); }
/** * Helper method to create a {@link SampleAdRequest}. * * @param mediationAdRequest The mediation request with targeting information. * @return The created {@link SampleAdRequest}. */ public SampleAdRequest createSampleRequest(MediationAdRequest mediationAdRequest) { SampleAdRequest request = new SampleAdRequest(); request.setTestMode(mediationAdRequest.isTesting()); request.setKeywords(mediationAdRequest.getKeywords()); return request; }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle mediationExtras) { if (SampleRewardedVideo.isAdAvailable()) { // Ad already available, use the forwarder to send a success callback to AdMob. mRewardedVideoEventForwarder.onAdLoaded(); } else { // No ad available, use the forwarder to send a failure callback. mRewardedVideoEventForwarder.onAdFailedToLoad(); } }
/** * Helper method to create a {@link SampleAdRequest}. * * @param mediationAdRequest The mediation request with targeting information. * @return The created {@link SampleAdRequest}. */ private SampleAdRequest createSampleRequest(MediationAdRequest mediationAdRequest) { SampleAdRequest request = new SampleAdRequest(); request.setTestMode(mediationAdRequest.isTesting()); request.setKeywords(mediationAdRequest.getKeywords()); return request; }
@Override public void requestInterstitialAd(Context context, CustomEventInterstitialListener listener, String serverParameter, MediationAdRequest mediationAdRequest, Bundle customEventExtras) { /* * In this method, you should: * * 1. Create your interstitial ad. * 2. Set your ad network's listener. * 3. Make an ad request. * * When setting your ad network's listener, don't forget to send the following callbacks: * * listener.onAdLoaded(this); * listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_*); * listener.onAdOpened(this); * listener.onAdLeftApplication(this); * listener.onAdClosed(this); */ mSampleInterstitial = new SampleInterstitial(context); // Here we're assuming the serverParameter is the ad unit for the Sample Ad Network. mSampleInterstitial.setAdUnit(serverParameter); // Implement a SampleAdListener and forward callbacks to mediation. mSampleInterstitial.setAdListener(new SampleCustomInterstitialEventForwarder(listener)); // Make an ad request. mSampleInterstitial.fetchAd(createSampleRequest(mediationAdRequest)); }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener mediationInterstitialListener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { try { AdapterParametersParser.Config config = AdapterParametersParser.parse(mediationExtras, serverParameters); mMediationInterstitialListener = mediationInterstitialListener; mVungleManager = VungleManager.getInstance(config.getAppId(), config.getAllPlacements()); mPlacementForPlay = mVungleManager.findPlacement(mediationExtras, serverParameters); mAdConfig = VungleExtrasBuilder.adConfigWithNetworkExtras(mediationExtras); mAdapterId = mId + String.valueOf(sCounter); sCounter++; mVungleManager.addListener(mAdapterId, mVungleListener); if (mVungleManager.isInitialized()) { loadAd(); } else { mVungleListener.setWaitingInit(true); mVungleManager.init(context); } } catch (IllegalArgumentException e) { if (mediationInterstitialListener != null) { mediationInterstitialListener .onAdFailedToLoad(VungleInterstitialAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } } }
@Override public void loadAd(MediationAdRequest adRequest, Bundle serverParameters, Bundle networkExtras) { mAdConfig = VungleExtrasBuilder.adConfigWithNetworkExtras(networkExtras); mPlacementForPlay = mVungleManager.findPlacement(networkExtras, serverParameters); if (mVungleManager.isAdPlayable(mPlacementForPlay)) { if (mMediationRewardedVideoAdListener != null) { mMediationRewardedVideoAdListener.onAdLoaded(VungleAdapter.this); } } else { mVungleListener.waitForAd(mPlacementForPlay); mVungleManager.loadAd(mPlacementForPlay); } }
/*************** * MediationInterstitialAdapter methods ***************/ @Override public void requestInterstitialAd(Context context, MediationInterstitialListener mediationInterstitialListener, Bundle serverParams, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { _adColonyInterstitialListener = new AdColonyAdListener(this, mediationInterstitialListener); // initialize AdColony boolean success = AdColonyManager.getInstance() .configureAdColony(context, serverParams, mediationAdRequest, mediationExtras); // if we were unable to configure, notify the listener if (success) { // configuration is successful // retrieve zones and request interstitial ad ArrayList<String> newZoneList = AdColonyManager.getInstance().parseZoneList(serverParams); String requestedZone = AdColonyManager.getInstance().getZoneFromRequest(newZoneList, mediationExtras); if (requestedZone != null) { // we have a valid zoneId -- request the ad AdColony.requestInterstitial(requestedZone, _adColonyInterstitialListener); } else { // a zone ID couldn't be retrieved, so notify that this ad couldn't be loaded. success = false; } } if (!success) { mediationInterstitialListener .onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); } }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle mediationExtras) { if (isInitialized()) { mRewardedVideoEventForwarder.loadAd(mediationExtras); } }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener listener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { mListenerInterstitial = listener; if (!(context instanceof Activity)) { Log.w(LOG_TAG, "Context not an Activity"); adFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST); } else { mActivity = (Activity) context; String apikey = serverParameters.getString("apiKey"); int spotId = Integer.parseInt(serverParameters.getString("spotId")); if (mediationExtras != null) { final InterstitialType type = (InterstitialType) mediationExtras.getSerializable(KEY_INTERSTITIAL_TYPE); if (type == InterstitialType.TYPE_VIDEO) { requestNendInterstialVideo(context, apikey, spotId, mediationExtras.getString(KEY_USER_ID, "")); return; } } requestNendInterstitial(context, apikey, spotId); } }
@Override public void requestBannerAd(Context context, MediationBannerListener mediationBannerListener, Bundle bundle, AdSize adSize, MediationAdRequest mediationAdRequest, Bundle bundle1) { String adunit = bundle.getString(MOPUB_AD_UNIT_KEY); mAdSize = adSize; mMoPubView = new MoPubView(context); mMoPubView.setBannerAdListener(new MBannerListener(mediationBannerListener)); mMoPubView.setAdUnitId(adunit); //If test mode is enabled if (mediationAdRequest.isTesting()) { mMoPubView.setTesting(true); } //If location is available if (mediationAdRequest.getLocation() != null) { mMoPubView.setLocation(mediationAdRequest.getLocation()); } mMoPubView.setKeywords(getKeywords(mediationAdRequest)); mMoPubView.loadAd(); }
private String getKeywords(MediationAdRequest mediationAdRequest) { StringBuilder keywordsBuilder = new StringBuilder(); keywordsBuilder = keywordsBuilder.append(MOPUB_NATIVE_CEVENT_VERSION) .append(mediationAdRequest.getBirthday() != null ? ",m_birthday:" + mediationAdRequest.getBirthday() : "") .append(mediationAdRequest.getGender() != -1 ? ",m_gender:" + mediationAdRequest.getGender() : ""); return keywordsBuilder.toString(); }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle networkExtras) { Log.i(TAG, "Loading ad for Tapjoy-AdMob adapter"); String loadAdPlacementName = ""; if (videoPlacementName == null || videoPlacementName.equals("")) { Log.i(TAG, "No placement name given for Tapjoy-AdMob adapter"); mediationRewardedVideoAdListener .onAdFailedToLoad(TapjoyAdapter.this, AdRequest.ERROR_CODE_INTERNAL_ERROR); return; } if (serverParameters != null && serverParameters.containsKey(PLACEMENT_NAME_SERVER_PARAMETER_KEY)) { loadAdPlacementName = serverParameters.getString(PLACEMENT_NAME_SERVER_PARAMETER_KEY); } if (!loadAdPlacementName.equals("") && !videoPlacementName.equals(loadAdPlacementName)) { // If incoming placement name is different from the one already preloaded, create new // placement videoPlacementName = loadAdPlacementName; createVideoPlacementAndRequestContent(); } else if (videoPlacement != null && videoPlacement.isContentReady()) { // If content is already available from previous request, fire success mediationRewardedVideoAdListener.onAdLoaded(TapjoyAdapter.this); } else { if (!videoPlacementIsRequesting) { // If we're not already in the middle of a request, send new placement request createVideoPlacementAndRequestContent(); } } }
@Override public void loadAd(@Nullable MediationAdRequest request, @Nullable Bundle bundle, @Nullable Bundle bundle1) { Log.d(TAG, "Load Ad"); if (mInterstitial != null) { mInterstitial.load(); } else { Log.d(TAG, "Ad failed to load: interstitial is null"); if (mListener != null) { mListener.onAdFailedToLoad( MyTargetRewardedAdapter.this, AdRequest.ERROR_CODE_INTERNAL_ERROR); } } }
/** * Starts loading banner. * * @param myTargetBannerListener listener for ad callbacks * @param mediationAdRequest Google mediation request * @param slotId myTarget slot ID * @param adSize myTarget banner size * @param context app context */ private void loadBanner(@Nullable MyTargetBannerListener myTargetBannerListener, @Nullable MediationAdRequest mediationAdRequest, int slotId, int adSize, @NonNull Context context) { if (mMyTargetView != null) { mMyTargetView.destroy(); } mMyTargetView = new MyTargetView(context); mMyTargetView.init(slotId, adSize, false); CustomParams params = mMyTargetView.getCustomParams(); if (mediationAdRequest != null) { int gender = mediationAdRequest.getGender(); params.setGender(gender); Log.d(TAG, "Set gender to " + gender); Date date = mediationAdRequest.getBirthday(); if (date != null && date.getTime() != -1) { GregorianCalendar calendar = new GregorianCalendar(); GregorianCalendar calendarNow = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); int age = calendarNow.get(GregorianCalendar.YEAR) - calendar.get(GregorianCalendar.YEAR); if (age >= 0) { Log.d(TAG, "Set age to " + age); params.setAge(age); } } } params.setCustomParam( MyTargetTools.PARAM_MEDIATION_KEY, MyTargetTools.PARAM_MEDIATION_VALUE); mMyTargetView.setListener(myTargetBannerListener); mMyTargetView.load(); }
@Override public void requestBannerAd(Context context, MediationBannerListener listener, Bundle serverParameters, AdSize adSize, MediationAdRequest adRequest, Bundle mediationExtras) { mBannerListener = listener; if (!isValidRequestParameters(context, serverParameters)) { mBannerListener.onAdFailedToLoad( FacebookAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } if (adSize == null) { Log.w(TAG, "Fail to request banner ad, adSize is null"); mBannerListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } String placementId = serverParameters.getString(PLACEMENT_PARAMETER); com.facebook.ads.AdSize facebookAdSize = getAdSize(context, adSize); if (facebookAdSize == null) { Log.w(TAG, "The input ad size " + adSize.toString() + " is not supported at this moment."); mBannerListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_NO_FILL); return; } mAdView = new AdView(context, placementId, facebookAdSize); mAdView.setAdListener(new BannerListener()); buildAdRequest(adRequest); RelativeLayout.LayoutParams adViewLayoutParams = new RelativeLayout.LayoutParams( adSize.getWidthInPixels(context), adSize.getHeightInPixels(context)); mWrappedAdView = new RelativeLayout(context); mAdView.setLayoutParams(adViewLayoutParams); mWrappedAdView.addView(mAdView); mAdView.loadAd(); }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener mediationInterstitialListener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle networkExtras) { mMediationInterstitialListener = mediationInterstitialListener; mChartboostParams = createChartboostParams(serverParameters, networkExtras); if (!isValidChartboostParams(mChartboostParams)) { // Invalid server parameters, send ad failed to load event. if (mMediationInterstitialListener != null) { mMediationInterstitialListener.onAdFailedToLoad(ChartboostAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (!ChartboostSingleton.startChartboostInterstitial(context, mChartboostInterstitialDelegate)) { // Chartboost initialization failed, send failed to load event. if (mMediationInterstitialListener != null) { mMediationInterstitialListener.onAdFailedToLoad(ChartboostAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } // Request ChartboostSingleton to load interstitial ads. mIsLoading = true; ChartboostSingleton.loadInterstitialAd(mChartboostInterstitialDelegate); }
@Override public void initialize(Context context, MediationAdRequest mediationAdRequest, String userId, MediationRewardedVideoAdListener mediationRewardedVideoAdListener, Bundle serverParameters, Bundle networkExtras) { mMediationRewardedVideoAdListener = mediationRewardedVideoAdListener; mChartboostParams = createChartboostParams(serverParameters, networkExtras); if (!isValidChartboostParams(mChartboostParams)) { // Invalid server parameters, send initialization failed event. if (mMediationRewardedVideoAdListener != null) { mMediationRewardedVideoAdListener.onInitializationFailed(ChartboostAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (!ChartboostSingleton.startChartboostRewardedVideo(context, mChartboostRewardedVideoDelegate)) { // Chartboost initialization failed, send initialization failed event. if (mMediationRewardedVideoAdListener != null) { mMediationRewardedVideoAdListener.onInitializationFailed(ChartboostAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } } }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle networkExtras) { // Update mChartboostParams before loading ads. mChartboostParams = createChartboostParams(serverParameters, networkExtras); // Request singleton to load rewarded video ad. mIsLoading = true; ChartboostSingleton.loadRewardedVideoAd(mChartboostRewardedVideoDelegate); }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener listener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { if (!(context instanceof Activity)) { listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } MaioAds.setAdTestMode(mediationAdRequest.isTesting()); this.mMediationInterstitialListener = listener; loadServerParameters(serverParameters); if (!isInitialized()) { //maio sdk initialization MaioEventForwarder.initialize((Activity) context, this.mMediaId); } if (MaioAds.canShow(this.mInterstitialZoneId)) { if (this.mMediationInterstitialListener != null) { this.mMediationInterstitialListener.onAdLoaded(Interstitial.this); } } else { if (this.mMediationInterstitialListener != null) { this.mMediationInterstitialListener .onAdFailedToLoad(Interstitial.this, AdRequest.ERROR_CODE_NO_FILL); } } }
@Override public void requestInterstitialAd(Context context, MediationInterstitialListener mediationInterstitialListener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { mMediationInterstitialListener = mediationInterstitialListener; String gameId = serverParameters.getString(KEY_GAME_ID); mPlacementId = serverParameters.getString(KEY_PLACEMENT_ID); if (!isValidIds(gameId, mPlacementId)) { if (mMediationInterstitialListener != null) { mMediationInterstitialListener.onAdFailedToLoad(UnityAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (!isValidContext(context)) { return; } // Check if the Unity Ads initialized successfully. if (!UnitySingleton.initializeUnityAds(mUnityAdapterDelegate, (Activity) context, gameId)) { if (mMediationInterstitialListener != null) { mMediationInterstitialListener.onAdFailedToLoad(UnityAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } // Storing a weak reference to the Activity. mActivityWeakReference = new WeakReference<>((Activity) context); // Unity Ads initialized successfully, request UnitySingleton to load ads for mPlacementId. mIsLoading = true; UnitySingleton.loadAd(mUnityAdapterDelegate); }
@Override public void initialize(Context context, MediationAdRequest mediationAdRequest, String userId, MediationRewardedVideoAdListener mediationRewardedVideoAdListener, Bundle serverParameters, Bundle networkExtras) { mMediationRewardedVideoAdListener = mediationRewardedVideoAdListener; String gameId = serverParameters.getString(KEY_GAME_ID); mPlacementId = serverParameters.getString(KEY_PLACEMENT_ID); if (!isValidIds(gameId, mPlacementId)) { if (mMediationRewardedVideoAdListener != null) { mMediationRewardedVideoAdListener.onInitializationFailed(UnityAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (!isValidContext(context)) { return; } // Check if the Unity Ads initialized. if (!UnitySingleton.initializeUnityAds(mUnityAdapterDelegate, (Activity) context, gameId)) { if (mMediationRewardedVideoAdListener != null) { mMediationRewardedVideoAdListener.onInitializationFailed(UnityAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } // Storing a weak reference to the Activity. mActivityWeakReference = new WeakReference<>((Activity) context); mIsRewardedVideoAdAdapterInitialized = true; mMediationRewardedVideoAdListener.onInitializationSucceeded(this); }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle networkExtras) { // Request UnitySingleton to load ads for mPlacementId. mIsLoading = true; mPlacementId = serverParameters.getString(KEY_PLACEMENT_ID); if (!isValidIds(serverParameters.getString(KEY_GAME_ID), mPlacementId)) { mMediationRewardedVideoAdListener.onAdFailedToLoad( UnityAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } UnitySingleton.loadAd(mUnityAdapterDelegate); }
@Override public void initialize(final Context context, final MediationAdRequest adRequest, final String userId, final MediationRewardedVideoAdListener listener, final Bundle serverParameters, final Bundle networkExtras) { if (!validateContext(context)) { log(ERROR, "Unable to request AppLovin rewarded video. Invalid context provided."); listener.onInitializationFailed(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } log(DEBUG, "Initializing AppLovin rewarded video..."); this.mContext = context; mRewardedAdMobListener = listener; this.mServerParameters = serverParameters; if (!mInitialized) { mRewardedSdk = sdkInstance(context); mInitialized = true; mRewardedAd = AppLovinIncentivizedInterstitial.create(mRewardedSdk); mAppLovinAdListener = new AppLovinAdListener(this, mRewardedAdMobListener); } mRewardedAdMobListener.onInitializationSucceeded(this); }
@Override public void loadAd(final MediationAdRequest adRequest, final Bundle serverParameters, final Bundle networkExtras) { log(DEBUG, "Requesting AppLovin rewarded video"); if (mRewardedAd.isAdReadyToDisplay()) { mRewardedAdMobListener.onAdLoaded(this); } else { mRewardedAd.preload(mAppLovinAdListener); } }
private void isTaggedForChildDirectedTreatment(MediationAdRequest mediationAdRequest, HashMap<String, String> paramMap) { if (mediationAdRequest.taggedForChildDirectedTreatment() == MediationAdRequest.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE) { paramMap.put("coppa", "1"); } else paramMap.put("coppa", "0"); }
@Override public void loadAd(MediationAdRequest mediationAdRequest, Bundle serverParameters, Bundle networkExtras) { if (mAdRewarded != null) { mAdRewarded.load(); } }
@Override public void initialize(final Context context, final MediationAdRequest adRequest, final String userId, final MediationRewardedVideoAdListener listener, final Bundle serverParameters, final Bundle networkExtras) { // SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) ) { log( ERROR, "Unable to request AppLovin rewarded video. Invalid context provided." ); listener.onInitializationFailed( this, AdRequest.ERROR_CODE_INVALID_REQUEST ); return; } log( DEBUG, "Initializing AppLovin rewarded video..." ); this.context = context; this.listener = listener; if ( !initialized ) { AppLovinSdk.initializeSdk( context ); AppLovinSdk.getInstance( context ).setPluginVersion( "AdMob-2.0" ); initialized = true; } listener.onInitializationSucceeded( this ); }
@Override public void loadAd(final MediationAdRequest adRequest, final Bundle serverParameters, final Bundle networkExtras) { log( DEBUG, "Requesting AppLovin rewarded video with networkExtras: " + networkExtras ); // Zones support is available on AppLovin SDK 7.5.0 and higher final String zoneId; if ( AppLovinSdk.VERSION_CODE >= 750 && networkExtras != null && networkExtras.containsKey( "zone_id" ) ) { zoneId = networkExtras.getString( "zone_id" ); } else { zoneId = DEFAULT_ZONE; } // Check if incentivized ad for zone already exists if ( GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.containsKey( zoneId ) ) { incentivizedInterstitial = GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.get( zoneId ); } else { // If this is a default Zone, create the incentivized ad normally if ( DEFAULT_ZONE.equals( zoneId ) ) { incentivizedInterstitial = AppLovinIncentivizedInterstitial.create( this.context ); } // Otherwise, use the Zones API else { incentivizedInterstitial = createIncentivizedInterstitialForZoneId( zoneId, AppLovinSdk.getInstance( this.context ) ); } GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.put( zoneId, incentivizedInterstitial ); } incentivizedInterstitial.preload( this ); }