Add custom repository.
repositories { maven { setUrl("https://sdk-cdn.mediafy.io/android/mediafy-sdk") } }
Add Gradle imports.
implementation("com.mediafy:mediafy-sdk:2.4.4") implementation("com.mediafy:mediafy-sdk-applovin-adapters:2.4.4")
Mediafy.initializeSdk(context, accountSettings)
Parameters:
context
accountSettings
val initConfig = AppLovinSdkInitializationConfiguration .builder("<SDK_ID>", this) .setMediationProvider(AppLovinMediationProvider.MAX) .build() AppLovinSdk.getInstance(this).initialize(initConfig) { Log.d("ApplovinInitialization", "Initialization result: $it") }
<SDK_ID>
Banner and Interstitial formats don't require any additional effort. The mediation engine of GMA SDK will manage everything according to the Custom Network and Custom events setup. See the AdOps Guide for the details.
Creating AppLovin banner with Mars adapter.
Important: AppLovin Ad Unit must be "Manual" type. Or native ad will not be rendered correctly.
private fun createAd() { // 1. Create MaxNativeAdLoader appLovinLoader = MaxNativeAdLoader(appLovinAdUnitId, this) // 2. Create native ad config and set it to local extras val nativeAdConfig = createNativeConfig() appLovinLoader?.setLocalExtraParameter(MediafyNativeAdConfig.KEY_EXTRAS, nativeAdConfig) appLovinLoader?.setNativeAdListener(createListener(containerForAd)) // 3. Create custom native view val adView = createCustomView() // 4. Load ad appLovinLoader?.loadAd(adView) }
Create AppLovin MaxNativeAdLoader providing AppLovin ad unit id.
MaxNativeAdLoader
Create MediafyNativeAdConfig with required assets, native event trackers, context and placement types. In the example we request: CTA text, title, icon, image, rating, and description. After creating convert it to Bundle for AdMob.
MediafyNativeAdConfig
private fun createNativeConfig(): MediafyNativeAdConfig { val ctaText = NativeDataAsset(NativeDataAsset.DataType.CTATEXT) ctaText.len = 15 val title = NativeTitleAsset(90) title.isRequired = true val icon = NativeImageAsset() icon.wMin = 50 icon.hMin = 50 icon.imageType = NativeImageAsset.ImageType.ICON val image = NativeImageAsset() image.w = 1200 image.h = 627 image.imageType = NativeImageAsset.ImageType.MAIN image.isRequired = true val rating = NativeDataAsset(NativeDataAsset.DataType.RATING) val description = NativeDataAsset(NativeDataAsset.DataType.DESC) description.isRequired = true description.len = 150 val assets = listOf(ctaText, title, icon, image, rating, description) val methods: ArrayList<EventTrackingMethod> = ArrayList() methods.add(EventTrackingMethod.IMAGE) methods.add(EventTrackingMethod.JS) val tracker = NativeEventTracker(NativeEventTracker.EventType.IMPRESSION, methods) val config = MediafyNativeAdConfig() config.setContextType(NativeContextType.SOCIAL_CENTRIC) config.setPlacementType(NativePlacementType.CONTENT_FEED) config.setContextSubType(NativeContextSubtype.GENERAL_SOCIAL) config.setNativeEventTrackers(listOf(tracker)) config.setNativeAssets(assets) return config }
Create custom native ad for your UI.
private fun createCustomView(): MaxNativeAdView { val builder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.view_native_ad_max) .setTitleTextViewId(R.id.tvHeadline) .setBodyTextViewId(R.id.tvBody) .setIconImageViewId(R.id.imgIco) .setMediaContentViewGroupId(R.id.frameMedia) .setCallToActionButtonId(R.id.btnCallToAction) .build() val adView = MaxNativeAdView(builder, this) return adView }
Load and display ad.
You can create and set custom ad events listener.