Integrate ads
Implementation
Set the VFAdInterface to your PreviewCommentsFragment
VFPreviewCommentsFragment previewCommentsFragment = VFPreviewCommentsFragment.newInstance(articleViewModel.getStory().getContainerId(), articleMetadata, this, vfSettings);
previewCommentsFragment.setAdInterface(this);
val previewCommentsFragment = PreviewCommentsFragment.newInstance(articleViewModel.getStory().getContainerId(), articleMetadata, this, vfSettings)
previewCommentsFragment.setAdInterface(this)
Integrate Google Ads
Integrate Google Ads into your application. Make sure to initialize the Google Ads SDK. Google Ads Quick Start
@Override
public ViewGroup generateAd(VFFragment fragment, int adPosition) {
RelativeLayout adContainer = new RelativeLayout(this);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
adView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300));
adContainer.addView(adView);
return adContainer;
}
@Override
public int getFirstAdPosition(VFFragment fragment) {
return 5;
}
@Override
public int getAdInterval(VFFragment fragment) {
return 3;
}
fun generateAd(adPosition: Int, fragment: VFFragment): ViewGroup ? {
val adContainer = RelativeLayout(this)
val adView = AdView(this)
adView.setAdSize(AdSize.BANNER)
adView.adUnitId = "ca-app-pub-3940256099942544/6300978111"
val adRequest: AdRequest = Builder()
.build()
adView.loadAd(adRequest)
adView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)
adContainer.addView(adView)
return adContainer
}
Integrate your custom ads
@Override
public ViewGroup generateAd(VFFragment fragment, int adPosition) {
String service = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getApplicationContext().getSystemService(service);
RelativeLayout adLayout = (RelativeLayout) li.inflate(R.layout.row_ad, null);
return adLayout;
}
@Override
public int getFirstAdPosition(VFFragment fragment) {
return 5;
}
@Override
public int getAdInterval(VFFragment fragment) {
return 3;
}
fun generateAd(adPosition: Int, fragment: VFFragment): ViewGroup ? {
val service: String = Context.LAYOUT_INFLATER_SERVICE
val li = getApplicationContext().getSystemService(service) as LayoutInflater
return li.inflate(R.layout.row_ad, null) as RelativeLayout
}
Updated 12 months ago
What’s Next