Standalone SDK - Android - Appier Ads SDK

文章推薦指數: 80 %
投票人數:10人

We have 3 parts to integrate Appier Mobile SDK for Android Integrating Appier Mobile SDKListView and RecyclerViewAdvanced Usage Current Support Ad Format ... DocumentationGettingStartedwithAppierAdsAppPublishersOverviewAndroidSDKAdMobMediationSDK-AndroidStandaloneSDK-AndroidAndroidSampleAppiOSSDKAdMobMediationSDK-iOSiOSSampleApp(Swift)WebPublishersAPNBannerPreferredDeal(PD)BannerVideoHeaderBidding(Prebid.js)PublisherPortalOverviewFAQFrequentlyAskedQuestionsContactUsPublisherPartnershipsTechnicalSupportPoweredby AppierAndroidSDK Wehave3partstointegrateAppierMobileSDKforAndroid IntegratingAppierMobileSDK ListViewandRecyclerView AdvancedUsage CurrentSupportAdFormat NativeAds BannerAds InterstitialAds Video 1.IntegratingAppierMobileSDK Step1-Prerequisites Makesureyourapp'sAPIlevel>=18 Step2-GradleConfiguration Pleaseaddjcentertoyourrepositories. build.gradlerepositories{ //... mavenCentral() } dependencies{ implementation'com.appier:ads-android:2.0.0' } Step3-ManifestConfiguration Topreventyourappfromcrashing,followingaretherecommendedmanifestconfigurations. Manifest.xml Thefollowingnetworksecurityconfigurationisalsorequired.Withoutthisconfig,httptrafficswillbeblockedinandroid9andhigher. Manifest.xml ... res/xml/network_security_config.xml Step4-GDPRConsent(Recommended) InconsenttoGDPR,westronglyrecommendtosettheconsentstatustoourSDKviaAppier.setGDPRApplies()sothatAppierSdkdoesnottrackusers'personalinformation.Withoutthisconfiguration,AppierwillNOTapplyGDPRbydefault. Notethatthiswillimpacttheadvertisingperformancehenceimpacttherevenue. MainActivity.javaimportcom.appier.ads.Appier; publicclassMainActivityextendsAppCompatActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ //... Appier.setGDPRApplies(true); } } Step5-AdFormatIntegration Overview 5.1-NativeAds 5.2-BannerAds 5.3-InterstitialAds 5.4-VideoAds 5.1-NativeAds PrepareAdView Nativeallowsyoutocustomizeyourownadlayout.Youcaneitherdesignyoursorusethefollowingsample. LoadAd Tosetupanativead,youneedtoimplementAppierNativeAd.EventListeneranddefinezoneId.Then,useloadAd()torequestads.Toshowtheloadedad,youcanaccesstherenderedadviewviaappierNativeAd.getAdView()andattachtowhereveryouwant. Destroyad Onceyounolongerusethead,pleasedestroyittopreventmemoryleak. PrepareAdViewLoadAdDestroyAd AppierNativeAdappierNativeAd=newAppierNativeAd(someContext,newAppierAdUnitIdentifier(""),newAppierNativeAd.EventListener(){ @Override publicvoidonAdLoaded(AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdLoaded()"); ViewadView=appierNativeAd.getAdView(); LinearLayoutadContainer=findViewById(R.id.ad_container); adContainer.addView(adView); } @Override publicvoidonAdNoBid(AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdNoBid()"); } @Override publicvoidonAdLoadFail(AppierErrorappierError,AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdLoadFail()",appierError.toString()); } @Override publicvoidonAdShown(AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdShown()"); } @Override publicvoidonImpressionRecorded(AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onImpressionRecorded()"); } @Override publicvoidonImpressionRecordFail(AppierErrorappierError,AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onImpressionRecordFail()",appierError.toString()); } @Override publicvoidonAdClick(AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdClick()"); } @Override publicvoidonAdClickFail(AppierErrorappierError,AppierNativeAdappierNativeAd){ Appier.log("[SampleApp]onAdClickFail()"); } }); appierNativeAd.setViewBinder(appierNativeViewBinder); appierNativeAd.setZoneId(""); appierNativeAd.loadAd(); if(appierNativeAd!=null){ appierNativeAd.destroy(); } 5.2-BannerAds LoadAd Tosetupabannerad,youneedtoimplementAppierBannerAd.EventListeneranddefinezoneId.Then,useloadAd()torequestads.Toshowtheloadedad,youcanaccesstherenderedadviewviaappierBannerAd.getView()andattachtowhereveryouwant. LoadAdAppierBannerAdappierBannerAd=newAppierBannerAd(context,newAppierAdUnitIdentifier(""),newAppierBannerAd.EventListener(){ @Override publicvoidonAdLoaded(AppierBannerAdappierBannerAd){ Appier.log("[SampleApp]","[Banner]","onAdLoaded()"); ViewadView=appierBannerAd.getView(); LinearLayoutadContainer=findViewById(R.id.ad_container); adContainer.addView(adView); } @Override publicvoidonAdNoBid(AppierBannerAdappierBannerAd){ Appier.log("[SampleApp]","[Banner]","onAdNoBid()"); } @Override publicvoidonAdLoadFail(AppierErrorappierError,AppierBannerAdappierBannerAd){ Appier.log("[SampleApp]","[Banner]","onAdLoadFail()",appierError.toString()); } @Override publicvoidonViewClick(AppierBannerAdappierBannerAd){ Appier.log("[SampleApp]","[Banner]","onViewClick()"); } }); appierBannerAd.setAdDimension(300,250); appierBannerAd.setZoneId(""); appierBannerAd.loadAd(); Shortcut Ifyouarenotgoingtointeractwithbanner'slifecycle,youcansimplyuseAppierBannerViewasanadunit. XML Similartoabove,youneedtodefineAdDimensionandzoneId.Then,useloadAd()torequestads.AppierBannerViewwillautomaticallyshowtheadonceitisloaded. JavaAppierBannerViewappierBannerView=findViewById(R.id.ad_container); appierBannerView.setAdDimension(300,250); appierBannerView.setZoneId(""); appierBannerView.loadAd(); Destroyad Onceyounolongerusethead,pleasedestroyittopreventmemoryleak.Useeitheroneoffollowingsamplesaccordingly. Javaif(appierBannerAd!=null){ appierBannerAd.destroy(); } Javaif(appierBannerView!=null){ appierBannerView.destroy(); } 5.3-InterstitialAds LoadAd TheminimalsetuptoprepareaninterstitialrequirestodefineAppierInterstitialAd.EventListener,AdDimensionandzoneId.Then,useloadAd()torequestads. ShowAd Oncetheadisloaded,youcanuseshowAd()todisplayit.Beforeshowingthead,wesuggestyoutoverifywhethertheadisavailableviaisLoaded().IfinterstitialisnotreadywhenyoucallshowAd(),therewillbeno-ops. DestroyAd Onceyounolongerusethead,pleasedestroyittopreventmemoryleak. LoadAdShowAdDestroyAdAppierInterstitialAdappierInterstitialAd=newAppierInterstitialAd(this,newAppierAdUnitIdentifier(""),newAppierInterstitialAd.EventListener(){ @Override publicvoidonAdLoaded(AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialloaded"); } @Override publicvoidonAdNoBid(AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialadreturnsnobid"); } @Override publicvoidonAdLoadFail(AppierErrorappierError,AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialloadfailed"); } @Override publicvoidonShown(AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialshown"); } @Override publicvoidonShowFail(AppierErrorappierError,AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialshowfailedwitherror:"+appierError); } @Override publicvoidonDismiss(AppierInterstitialAdappierInterstitialAd){ Appier.log("[SampleApp]","Interstitialdismissed"); //YoucandestroyInterstitialheretopreventfrommemoryleak interstitialAd.destroy(); } }); appierInterstitialAd.setAdDimension(300,250); appierInterstitialAd.setZoneId(""); appierInterstitialAd.loadAd(); if(appierInterstitialAd.isLoaded()){ appierInterstitialAd.showAd(); } if(appierInterstitialAd!=null){ appierInterstitialAd.destroy(); } 5.4-VideoAds LoadAd TheminimalsetuptoprepareavideorequirestodefineVideoAd.EventListener,zoneId.Then,useloadAd()torequestads. ShowAd Oncetheadisloaded,youcanshowAd()todisplayit.Beforeshowingthead,wesuggestyoutoverifywhethertheadisavailableviaisLoaded().IfvideoisnotreadywhenyoucallshowAd(),therewillbeno-ops. DestroyAd Onceyounolongerusethead,pleasedestroyittopreventmemoryleak. AdvancedUsage YoucanusesetOrientation()tosetvideoadorientationbeforeloadAd(),ortheadorientationwouldbethescreenorientationwhenyoucalledloadAd() LoadAdShowAdDestroyAdAdvancedUsageimportcom.appier.ads.VideoAd; //... VideoAdvideoAd=newVideoAd(this,newAppierAdUnitIdentifier(""),newVideoAd.EventListener(){ @Override publicvoidonAdLoaded(VideoAdvideoAd){ Appier.log("[SampleApp]","Videoloaded"); } @Override publicvoidonAdNoBid(VideoAdvideoAd){ Appier.log("[SampleApp]","Videoadreturnsnobid"); } @Override publicvoidonAdLoadFail(AppierErrorappierError,VideoAdvideoAd){ Appier.log("[SampleApp]","Videoloadfailed"); } @Override publicvoidonViewClick(VideoAdvideoAd){ Appier.log("[SampleApp]","Videoclicked"); } @Override publicvoidonViewClickFail(AppierErrorappierError,VideoAdvideoAd){ Appier.log("[SampleApp]","Videoclickfailed"); } @Override publicvoidonShown(VideoAdvideoAd){ Appier.log("[SampleApp]","Videoshown"); } @Override publicvoidonAdVideoComplete(VideoAdvideoAd){ Appier.log("[SampleApp]","Videocomplete"); } @Override publicvoidonShowFail(AppierErrorappierError,VideoAdvideoAd){ Appier.log("[SampleApp]","Videoshowfailedwitherror:"+appierError); } @Override publicvoidonDismiss(VideoAdvideoAd){ Appier.log("[SampleApp]","Videodismissed"); //Youcandestroyvideoheretopreventfrommemoryleak videoAd.destroy(); } }); videoAd.setZoneId(""); videoAd.loadAd(); if(videoAd.isLoaded()){ videoAd.showAd(); } if(videoAd!=null){ videoAd.destroy(); } videoAd.setZoneId(""); //SetAppiervideoadorientation videoAd.setOrientation(Configuration.ORIENTATION_PORTRAIT); //orvideoAd.setOrientation(Configuration.ORIENTATION_LANDSCAPE); videoAd.loadAd(); 2.ListViewandRecyclerView AppierSDKsupportstoinsertnativeorbannerintoListVieworRecyclerView.YouwillneedtowrapyourownoriginaladapterwithinAppierAdAdapterorAppierRecyclerAdapter.ThenusewrappedAdapter.insertAd()tocontroltheinsertion. ListView PrepareaListViewinyourlayout. XML Then,wraptheoriginaladapterwithinAppierAdAdapterandsettolistview. JavaArrayAdapter<...>adapter=newArrayAdapter(...); ListViewlistView=findViewById(R.id.list); AppierAdAdapterappierAdAdapter=newAppierAdAdapter(adapter); listView.setAdapter(appierAdAdapter); Createanormalnative(orbanner),andchooseaninsertPositiontoinsertwhentheadisloaded. JavaAppierNativeAdappierNativeAd=newAppierNativeAd(someContext,newAppierAdUnitIdentifier(""),newAppierNativeAd.EventListener(){ @Override publicvoidonAdLoaded(AppierNativeAdappierNativeAd){ try{ appierAdAdapter.insertAd(insertPosition,appierNativeAd); }catch(Exceptione){ Appier.log("[SampleApp]Failtoinsertadintolist.Maybethepositionisoutofboundorisalreadyused."); } } //... }); RecyclerView PrepareaRecyclerViewinyourlayout. XML Then,wraptheoriginaladapterwithinAppierRecyclerAdapterandsettorecyclerview. JavaMyRecyclerViewAdapteradapter=newMyRecyclerViewAdapter(...); RecyclerViewrecyclerView=findViewById(R.id.recycler); recyclerView.setLayoutManager(newLinearLayoutManager(this)); AppierRecyclerAdapterappierRecyclerAdapter=newAppierRecyclerAdapter(adapter); recyclerView.setAdapter(appierRecyclerAdapter); Createanormalbanner(ornative),andchooseaninsertPositiontoinsertwhentheadisloaded. JavaAppierBannerAdappierBannerAd=newAppierBannerAd(this,newAppierAdUnitIdentifier(""),newAppierBannerAd.EventListener(){ @Override publicvoidonAdLoaded(AppierBannerAdappierBannerAd){ try{ appierRecyclerAdapter.insertAd(insertPosition,appierBannerAd); }catch(Exceptione){ Appier.log("[SampleApp]Failtoinsertadintolist.Maybethepositionisoutofboundorisalreadyused."); } } //... }); 3.AdvancedUsage EnableTestingMode TomakedeveloperstesttheSDKintegrationeasily,youcanenabletestmodegloballyviaAppier.setTestMode.Intestmode,AppierSDKbydefaultwillforcebid.YoucanalsosettodifferentAppier.TestModetoensureSDK'sbehavior. JavaAppier.setTestMode(true);//SameasAppier.TestMode.BID Appier.setTestMode(false);//SameasAppier.TestMode.FALSE Appier.setTestMode(Appier.TestMode.FALSE); Appier.setTestMode(Appier.TestMode.BID); Appier.setTestMode(Appier.TestMode.NO_BID); SetTargeting Foralladformats,youcanoptionallysettargetingviafollowingmethods: setYob() setGender() addKeyword() Java//Banner appierBannerView.setYob(2001); appierBannerView.setGender(AppierTargeting.Gender.FEMALE); appierBannerView.addKeyword("interest","sports"); //Interstitial appierInterstitialAd.setYob(2001); appierInterstitialAd.setGender(AppierTargeting.Gender.MALE); appierInterstitialAd.addKeyword("interest","sports"); //Native mAppierNativeAd.setYob(2001); mAppierNativeAd.setGender(AppierTargeting.Gender.OTHER); mAppierNativeAd.addKeyword("interest","sports"); Updated5monthsagoTableofContents AppierAndroidSDK 1.IntegratingAppierMobileSDK 2.ListViewandRecyclerView 3.AdvancedUsage



請為這篇文章評分?