private MyTargetView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
// Enabling debug mode
// MyTargetView.setDebugMode(true);
// Create an instance of MyTargetView
adView = new MyTargetView(this);
// Set slot id
adView.setSlotId(YOUR_SLOT_ID);
// optional: if not set, banner will be adaptive
adView.setAdSize(AdSize.ADSIZE_320x50);
}
private MyTargetView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.activityLayout);
// Create an instance of MyTargetView
adView = new MyTargetView(this);
// Set slot id
adView.setSlotId(YOUR_SLOT_ID);
// Set the LayoutParams
adViewLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setLayoutParams(adViewLayoutParams);
// Set the event listener
adView.setListener(new MyTargetView.MyTargetViewListener()
{
@Override
public void onLoad(MyTargetView myTargetView)
{
// The ad is successfully loaded. Start displaying ad
layout.addView(adView);
}
@Override
public void onNoAd(String reason, MyTargetView myTargetView)
{
}
@Override
public void onShow(MyTargetView myTargetView)
{
}
@Override
public void onClick(MyTargetView myTargetView)
{
}
});
// Start loading ad
adView.load();
}
@Override
protected void onDestroy()
{
if (adView != null) adView.destroy();
super.onDestroy();
}
<com.my.target.ads.MyTargetView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/view_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:myTarget_isRefreshAd="false" // turning off banner rotation
app:myTarget_adSize="banner_320x50" // set format, possible values: banner_320x50, banner_30x250, banner_728x90, adaptive
app:myTarget_slotId="7250"> // slot number
</com.my.target.ads.MyTargetView>
// Disable automatic ad rotation
adView.setRefreshAd(false);
private InterstitialAd ad;
private void initAd()
{
// Enabling debug mode
// MyTargetManager.setDebugMode(true);
// Create an instance of InterstitialAd
ad = new InterstitialAd(YOUR_SLOT_ID, this);
}
private InterstitialAd ad;
private void initAd()
{
// Create an instance of InterstitialAd
ad = new InterstitialAd(YOUR_SLOT_ID, this);
// Set the event listener
interstitialAd.setListener(new InterstitialAd.InterstitialAdListener()
{
@Override
public void onLoad(InterstitialAd ad)
{
}
@Override
public void onNoAd(String reason, InterstitialAd ad)
{
}
@Override
public void onClick(InterstitialAd ad)
{
}
@Override
public void onDisplay(InterstitialAd ad)
{
}
@Override
public void onDismiss(InterstitialAd ad)
{
}
@Override
public void onVideoCompleted(InterstitialAd ad)
{
}
});
// Start loading ad
ad.load();
}
@Override
public void onLoad(InterstitialAd ad)
{
// Start displaying
// in a separate Activity
ad.show();
}
private RewardedAd ad;
private void initAd()
{
// Turn on debug mode
// MyTargetManager.setDebugMode(true);
// Create instance of RewardedAd
ad = new RewardedAd(YOUR_SLOT_ID, this);
}
private RewardedAd ad;
private void initAd()
{
// Creating RewardedAd instance
ad = new RewardedAd(YOUR_SLOT_ID, this);
// Set listener
ad.setListener(new RewardedAd.RewardedAdListener()
{
@Override
public void onLoad(RewardedAd ad)
{
}
@Override
public void onNoAd(String reason, RewardedAd ad)
{
}
@Override
public void onClick(RewardedAd ad)
{
}
@Override
public void onDisplay(RewardedAd ad)
{
}
@Override
public void onDismiss(RewardedAd ad)
{
}
@Override
void onReward(@NonNull Reward reward, @NonNull RewardedAd ad)
{
}
});
// Start loading
ad.load();
}
@Override
public void onLoad(RewardedAd ad)
{
// Start showing
ad.show();
}
Reward.type;
private NativeAd ad;
private void initAd()
{
// Enabling debug mode
// MyTargetManager.setDebugMode(true);
// Create an instance of NativeAd
ad = new NativeAd(YOUR_SLOT_ID, this);
}
private NativeAd ad;
private void initAd()
{
// Create an instance of NativeAd
ad = new NativeAd(YOUR_SLOT_ID, this);
// Set the event listener
ad.setListener(new NativeAd.NativeAdListener()
{
@Override
public void onLoad(NativePromoBanner banner, NativeAd ad)
{
}
@Override
public void onNoAd(String reason, NativeAd ad)
{
}
@Override
public void onClick(NativeAd ad)
{
}
@Override
public void onShow(NativeAd ad)
{
}
@Override
public void onVideoPlay(NativeAd ad)
{
}
@Override
public void onVideoPause(NativeAd ad)
{
}
@Override
public void onVideoComplete(NativeAd ad)
{
}
});
// Start loading ad
ad.load();
}
ad.setCachePolicy(CachePolicy.NONE);
ad.load();
ad.setMediaListener(new NativeAdMediaListener() {
@Override
public void onIconLoad(@NonNull NativeAd ad)
{
// icon upload success notification
}
@Override
public void onImageLoad(@NonNull NativeAd ad)
{
// notification of successful upload of the main image
}
});
ad.load();
@Override
public void onLoad(NativePromoBanner banner, NativeAd ad)
{
// Ad title
String title = banner.getTitle();
// Main text
String description = banner.getDescription();
// Age limit. May be null
String ageRestrictions = banner.getAgeRestrictions();
// Disclaimer. May be null
String disclaimer = banner.getDisclaimer();
// "Advertising" label text
String advertisingLabel = banner.getAdvertisingLabel();
// Icon
ImageData icon = banner.getIcon();
// Call-to-action text for the button
String ctaText = banner.getCtaText();
// Properties available only for ads promoting apps
if (banner.getNavigationType().equals(NavigationType.STORE))
{
// App rating (0-5)
float rating = banner.getRating();
// Number of votes
int votes = banner.getVotes();
// App category
String category = banner.getCategory();
// App subcategory
String subcategory = banner.getSubcategory();
}
// Properties available only for ads promoting websites
else if (banner.getNavigationType().equals(NavigationType.WEB))
{
// Website domain
String domain = banner.getDomain();
}
// Use properties to build your visual component
Context context = YourActivity.this;
LinearLayout adViewLayout = new LinearLayout(context);
adViewLayout.setId(R.id.nativeads_ad_view);
TextView titleView = new TextView(context);
titleView.setId(R.id.nativeads_title);
titleView.setText(title);
adViewLayout.addView(titleView);
TextView descriptionView = new TextView(context);
descriptionView.setId(R.id.nativeads_description);
titleView.setText(description);
adViewLayout.addView(descriptionView);
Button btn = new Button(context);
btn.setId(R.id.nativeads_call_to_action);
btn.setText(ctaText);
adViewLayout.addView(btn);
// Create an instance of MediaAdView
MediaAdView mediaView = NativeViewsFactory.getMediaAdView(context);
mediaView.setId(R.id.nativeads_media_view);
// Create an instance of IconAdView
IconAdView iconView = new IconAdView(context);
mediaView.setId(R.id.nativeads_icon);
// If you have enabled autoloading of images, you can assign the loaded icon here: iconView.setImageBitmap(image.getBitmap());
adViewLayout.addView(mediaView);
adViewLayout.addView(iconView);
// Create container
NativeAdContainer nativeAdContainer = new NativeAdContainer(context);
// Add view to container
nativeAdContainer.addView(adViewLayout);
// Register the view
ad.registerView(adViewLayout);
// Add it to the layout
mainLayout.addView(nativeAdContainer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
...
ad.setAdChoicesPlacement(AdChoicesPlacement.TOP_RIGHT);
ad.load();
...
NativeAdChoicesView myAdChoicesView = createMyAdChoicesView(); // Creating your own NativeAdChoicesView
myAdChoicesView.setImageBitmap(bitmap);
myAdChoicesView.setImageDrawable(drawable);
...
...
ad.setAdChoicesPlacement(AdChoicesPlacement.MANUAL);
ad.load();
...
ad.setAdChoicesPlacement(AdChoicesPlacement.DRAWING_MANUAL);
ad.load();
...
customAdChoicesView.setOnClickListener(v->{
ad.handleAdChoicesClick(context)
})
//getting an AdChoises icon through a variable
ad.getBanner().getAdChoicesIcon();
...
//getting an AdChoises icon through the listener
ad.setAdChoicesListener(new NativeAd.NativeAdChoicesListener() {
@Override
public void onAdChoicesIconLoad(@Nullable ImageData imageData, boolean success, @NonNull NativeAd ad)
{
customAdChoicesView.setImageBitmap(imageData.getBitmap)
}
});
MenuFactory menuFactory = new MenuFactory()
{
@Override
@NonNull public Menu createMenu()
{
return new Menu()
{
@Override
public void setListener(@Nullable Listener listener)
{
//the listener that needs to call the onActionClick(menuAction) method when you click on the UI element that was drawn with the corresponding menuAction title
}
@Override
public void addAction(@NonNull MenuAction menuAction)
{
// this is an object that contains the header and option type of AdChoices, these objects should be used when drawing
}
@Override
public void present(@NonNull Context context)
{
// this method is called when you want to display AdChoices options with those menuActions that were previously obtained from the addAction() method
}
@Override
public void dismiss()
{
// this method is called when it is necessary to close the rendering of the AdChoices options
}
};
}
};
...
ad = new NativeAd(YOUR_SLOT_ID, menuFactory, this);
ad.load();
NativeAd.NativeAdChoicesOptionListener adChoicesOptionListener = new NativeAd.NativeAdChoicesOptionListener()
{
@Override
public boolean shouldCloseAutomatically()
{
return false;
}
@Override
public void onCloseAutomatically(@NonNull NativeBannerAd ad)
{
}
@Override
public void closeIfAutomaticallyDisabled(@NonNull NativeBannerAd ad)
{
}
};
ad.setAdChoicesOptionListener(adChoicesOptionListener);
@Override
public void onLoad(NativePromoBanner banner, NativeAd ad)
{
...
...
...
// Create an array of clickable visual components, titleView and cta button
ArrayList<View> clickableViews = new ArrayList<>();
clickableViews.add(titleView);
clickableViews.add(btn);
// Register the view with clickable titleView and button
ad.registerView(adViewLayout, clickableViews);
// Add it to the layout
mainLayout.addView(adViewLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
public void onLoad(NativePromoBanner banner, NativeAd ad)
{
// Create visual component
NativeAdView nativeAdView = NativeViewsFactory.getNativeAdView(ad, YourActivity.this);
// Available inner components
TextView advLabelView = nativeAdView.getAdvertisingTextView();
TextView ageRestrictionView = nativeAdView.getAgeRestrictionTextView();
TextView disclaimerView = nativeAdView.getDisclaimerTextView();
TextView titleView = nativeAdView.getTitleTextView();
TextView descriptionView = nativeAdView.getDescriptionTextView();
Button ctaBtn = nativeAdView.getCtaButtonView();
TextView votesView = nativeAdView.getVotesTextView();
StarsRatingView starsRatingView = nativeAdView.getStarsRatingView();
TextView domainView = nativeAdView.getDomainOrCategoryTextView();
MediaAdView mediaView = nativeAdView.getMediaAdView();
IconAdView iconView = nativeAdView.getIconImageView();
// Create container for creative
NativeAdContainer nativeAdContainer = new NativeAdContainer(context);
// Add ad creative to container
nativeAdContainer.addView(nativeAdView);
// Register visual component
ad.registerView(nativeAdContainer);
// Add to screen
mainLayout.addView(nativeAdContainer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
// Enabling debug mode
// MyTargetManager.setDebugMode(true);
// Create an instance of NativeAdLoader
NativeAdLoader nativeAdLoader = NativeAdLoader.newLoader(YOUR_SLOT_ID, COUNT, this);
// Set the OnLoad callback and loading ads
nativeAdLoader.setOnLoad(new OnLoad()
{
@Override
public void onLoad(@NonNull List<NativeAd> ads)
{
for (NativeAd ad : ads)
{
// Set the event listener
ad.setListener(nativeAdListener);
NativePromoBanner promoBanner = ad.getBanner();
// The same code as in onLoad method of NativeAdListener interface
}
}
}).load();
private NativeBannerAd ad;
private void initAd()
{
// Turn on debug mode
// MyTargetManager.setDebugMode(true);
// Creating instance of NativeBannerAd
ad = new NativeBannerAd(YOUR_SLOT_ID, this);
}
private NativeBannerAd ad;
private void initAd()
{
// Creating instance of NativeBannerAd
ad = new NativeBannerAd(YOUR_SLOT_ID, this);
// add listener
ad.setListener(new NativeBannerAd.NativeBannerAdListener()
{
@Override
public void onLoad(NativeBanner banner, NativeBannerAd ad)
{
}
@Override
public void onNoAd(String reason, NativeBannerAd ad)
{
}
@Override
public void onClick(NativeBannerAd ad)
{
}
@Override
public void onShow(NativeBannerAd ad)
{
}
});
// Start loading data
ad.load();
}
ad.setCachePolicy(CachePolicy.NONE);
ad.load();
ad.setMediaListener(new NativeBannerAdMediaListener() {
@Override
public void onIconLoad(@NonNull NativeBannerAd ad)
{
// icon upload success notification
}
});
ad.load();
@Override
public void onLoad(NativeBanner banner, NativeBannerAd ad)
{
// Ad Title
String title = banner.getTitle ();
// Age limit. May be null
String ageRestrictions = banner.getAgeRestrictions ();
// Disclaimer. May be null
String disclaimer = banner.getDisclaimer ();
// The text of the label "Advertising"
String advertisingLabel = banner.getAdvertisingLabel ();
// Icon
ImageData icon = banner.getIcon ();
// The action text for the button
String ctaText = banner.getCtaText ();
// Properties Available Only For Ads Promoting Applications
if (banner.getNavigationType (). equals (NavigationType.STORE))
{
// Application Rating (0-5)
float rating = banner.getRating ();
// Number of ratings
int votes = banner.getVotes ();
}
// Properties Available Only For Ads Promoting Websites
else if (banner.getNavigationType (). equals (NavigationType.WEB))
{
// site domain
String domain = banner.getDomain ();
}
// An example of filling a visual component
Context context = YourActivity.this;
LinearLayout adViewLayout = new LinearLayout (context);
adViewLayout.setId (R.id.nativeads_ad_view);
TextView titleView = new TextView (context);
titleView.setId (R.id.nativeads_title);
titleView.setText (title);
adViewLayout.addView (titleView);
Button btn = new Button (context);
btn.setId (R.id.nativeads_call_to_action);
btn.setText (ctaText);
adViewLayout.addView (btn);
IconAdView iconView = new IconAdView(context);
mediaView.setId (R.id.nativeads_icon);
adViewLayout.addView (iconView);
// Create a creative container
NativeAdContainer nativeAdContainer = new NativeAdContainer (context);
// Add ad creative to container
nativeAdContainer.addView (adViewLayout);
// Register the visual component
ad.registerView (adViewLayout);
// Add to the screen
mainLayout.addView (nativeAdContainer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
...
ad.setAdChoicesPlacement(AdChoicesPlacement.TOP_RIGHT);
ad.load();
...
NativeAdChoicesView myAdChoicesView = createMyAdChoicesView(); // creating own NativeAdChoicesView
myAdChoicesView.setImageBitmap(bitmap);
myAdChoicesView.setImageDrawable(drawable);
...
...
ad.setAdChoicesPlacement(AdChoicesPlacement.MANUAL);
ad.load();
...
ad.setAdChoicesPlacement(AdChoicesPlacement.DRAWING_MANUAL);
ad.load();
...
customAdChoicesView.setOnClickListener(v->{
ad.handleAdChoicesClick(context)
})
//getting an AdChoises icon through a variable
ad.getBanner().getAdChoicesIcon();
...
//getting an AdChoises icon through the listener
ad.setAdChoicesListener(new NativeBannerAd.NativeBannerAdChoicesListener() {
@Override
public void onAdChoicesIconLoad(@Nullable ImageData imageData, boolean success, @NonNull NativeAd ad)
{
customAdChoicesView.setImageBitmap(imageData.getBitmap)
}
});
MenuFactory menuFactory = new MenuFactory()
{
@Override
@NonNull public Menu createMenu()
{
return new Menu()
{
@Override
public void setListener(@Nullable Listener listener)
{
//the listener that needs to call the onActionClick(menuAction) method when you click on the UI element that was drawn with the corresponding menuAction title
}
@Override
public void addAction(@NonNull MenuAction menuAction)
{
// this is an object that contains the header and option type of AdChoices, these objects should be used when drawing
}
@Override
public void present(@NonNull Context context)
{
// this method is called when you want to display AdChoices options with those menuActions that were previously obtained from the addAction() method
}
@Override
public void dismiss()
{
// this method is called when it is necessary to close the rendering of the AdChoices options
}
};
}
};
...
ad = new NativeBannerAd(YOUR_SLOT_ID, menuFactory, this);
ad.load();
NativeBannerAd.NativeBannerAdChoicesOptionListener adChoicesOptionListener = new NativeBannerAd.NativeBannerAdChoicesOptionListener()
{
@Override
public boolean shouldCloseAutomatically()
{
return false;
}
@Override
public void onCloseAutomatically(@NonNull NativeBannerAd ad)
{
}
@Override
public void closeIfAutomaticallyDisabled(@NonNull NativeBannerAd ad)
{
}
};
ad.setAdChoicesOptionListener(adChoicesOptionListener);
@Override
public void onLoad(NativeBanner banner, NativeBannerAd ad)
{
...
...
...
// Create an array of clickable visual components, a title and a call to action button
ArrayList<View> clickableViews = new ArrayList<>();
clickableViews.add(titleView);
clickableViews.add(btn);
// Register the visual component, with a clickable title and a call to action button
ad.registerView(adViewLayout, clickableViews);
// Add to the screen
mainLayout.addView(adViewLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
public void onLoad(NativeBanner banner, NativeBannerAd ad)
{
// Create a visual component
NativeBannerAdView nativeBannerAdView = NativeViewsFactory.getNativeBannerAdView (YourActivity.this);
nativeBannerAdView.setupView(banner);
// Customizable internal visual components
TextView advLabelView = nativeBannerAdView.getAdvertisingTextView ();
TextView ageRestrictionView = nativeBannerAdView.getAgeRestrictionTextView ();
TextView disclaimerView = nativeBannerAdView.getDisclaimerTextView ();
TextView titleView = nativeBannerAdView.getTitleTextView ();
Button ctaBtn = nativeBannerAdView.getCtaButtonView ();
TextView votesView = nativeBannerAdView.getVotesTextView ();
StarsRatingView starsRatingView = nativeBannerAdView.getStarsRatingView ();
TextView domainView = nativeBannerAdView.getDomainOrCategoryTextView ();
IconAdView iconView = nativeBannerAdView.getIconImageView ();
// Create a creative container
NativeAdContainer nativeAdContainer = new NativeAdContainer (context);
// Add ad creative to container
nativeAdContainer.addView (nativeBannerAdView);
// Register the visual component
ad.registerView (nativeAdContainer);
// Add to the screen
mainLayout.addView (nativeAdContainer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
// Turn on debug mode
// MyTargetManager.setDebugMode(true);
// Creating NativeBannerAdLoader
NativeBannerAdLoader nativeBannerAdLoader = NativeBannerAdLoader.newLoader(YOUR_SLOT_ID, COUNT, this);
// Install OnLoad callback and load banners
nativeBannerAdLoader.setOnLoad(new OnLoad()
{
@Override
public void onLoad(@NonNull List<NativeBannerAd> ads)
{
for (NativeBannerAd ad : ads)
{
// add listener
ad.setListener(nativeBannerAdListener);
NativeBanner banner = ad.getBanner();
}
}
}).load();
private InstreamAd ad;
private void initAd()
{
// Enable debug mode
// MyTargetManager.setDebugMode(true);
// Instantiate InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
}
private InstreamAd ad;
private void initAd()
{
// Instantiate InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
// Install the player
ad.setPlayer(YOUR_PLAYER);
}
customAdChoicesView.setOnClickListener(v->
{
ad.handleAdChoicesClick(context)
})
MenuFactory menuFactory = new MenuFactory()
{
@Override
@NonNull public Menu createMenu()
{
return new Menu()
{
@Override
public void setListener(@Nullable Listener listener)
{
//the listener that needs to call the onActionClick(menuAction) method when you click on the UI element that was drawn with the corresponding menuAction title
}
@Override
public void addAction(@NonNull MenuAction menuAction)
{
// this is an object that contains the header and option type of AdChoices, these objects should be used when drawing
}
@Override
public void present(@NonNull Context context)
{
// this method is called when you want to display AdChoices options with those menuActions that were previously obtained from the addAction() method
}
@Override
public void dismiss()
{
// this method is called when it is necessary to close the rendering of the AdChoices options
}
};
}
};
...
ad = new InstreamAd(YOUR_SLOT_ID, menuFactory, this);
ad.load();
float getAdVideoDuration();
float getAdVideoPosition();
void setAdPlayerListener(AdPlayerListener listener);
View getView();
void setVolume(float volume);
void playAdVideo(Uri uri, int width, int height);
void pauseAdVideo();
void resumeAdVideo();
void stopAdVideo();
void onAdVideoStarted();
void onAdVideoPaused();
void onAdVideoResumed();
void onAdVideoStopped();
void onAdVideoError(String message);
void onAdVideoCompleted();
void onVolumeChanged(float volume);
private InstreamAd ad;
private void initAd()
{
// Create an instance of InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
// Install the player SDK
ad.useDefaultPlayer();
// Add player to the screen
layout.addView(ad.getPlayer().getView());
}
private InstreamAd ad;
private void initAd()
{
// Create an instance of InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
// Set the event listener
ad.setListener(new InstreamAd.InstreamAdListener()
{
@Override
public void onLoad(InstreamAd instreamAd)
{
// The data was successfully loaded
}
@Override
public void onNoAd(String reason, InstreamAd instreamAd)
{
// No data received
}
@Override
public void onError(String reason, InstreamAd ad)
{
// An error occurred while playing the promotional video
}
@Override
public void onBannerStart(InstreamAd ad, InstreamAd.InstreamAdBanner instreamAdBanner)
{
// Ad video playback is started
}
@Override
public void onBannerPause(InstreamAd ad, InstreamAd.InstreamAdBanner instreamAdBanner)
{
// Ad video playback is suspended
}
@Override
public void onBannerResume(InstreamAd ad, InstreamAd.InstreamAdBanner instreamAdBanner)
{
// Ad video playback is resumed
}
@Override
public void onBannerComplete(InstreamAd ad, InstreamAd.InstreamAdBanner instreamAdBanner)
{
// Ad video playback is finished
}
@Override
public void onBannerTimeLeftChange(float timeLeft, float duration, InstreamAd ad)
{
// Called repeatedly during the playback of a ad video, it is used to update the timer before the end of the ad video
}
@Override
public void onComplete(String section, InstreamAd ad)
{
// Playback of all ad videos in the promotional section is complete
}
@Override
public void onBannerShouldClose()
{
// Called when ad playback should be completed by the developer himself. Example: ad.skip()
}
});
// Start loading data
ad.load();
}
// Before starting the main video
ad.startPreroll();
// After showing the main video
ad.startPostroll();
private InstreamAd ad;
private void initAd()
{
// Create an instance of InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
// Set positions on the first and fifth seconds of the video
ad.configureMidpoints(videoDuration, new float[]{1f,5f});
// or percentage, 10% and 50% video
// ad.configureMidpointsPercents(videoDuration, new float[]{10f,50f});
// Set the event listener
ad.setListener(new InstreamAd.InstreamAdListener()
{
@Override
public void onLoad(InstreamAd instreamAd)
{
// The data was successfully loaded
// Array of positions (in seconds) available to display the midroll section
adPositions = ad.getMidPoints();
}
...
});
// Start loading data
ad.load();
}
// The video was played to the 5th second and it has a position in the array adPositions
ad.startMidroll(adPositions[1]);
public final float duration;
public final boolean allowClose;
public final float allowCloseDelay;
public final int videoWidth;
public final int videoHeight;
public String ctaText;
public boolean hasAdChoices;
public String advertisingLabel;
public ImageData adChoicesIcon;
private void onAdClick()
{
ad.handleClick();
}
public void pause()
public void resume()
public void stop()
public void skip()
public void skipBanner()
public void setVolume(float volume)
public void setLoadingTimeout(int loadingTimeout)
private InstreamAd ad;
private void initAd()
{
// Create an instance of InstreamAd
ad = new InstreamAd(YOUR_SLOT_ID, this);
// We receive an instance of additional parameters CustomParams
CustomParams customParams = ad.getCustomParams();
// Set age
customParams.setAge(25);
// Set gender
customParams.setGender(CustomParams.Gender.MALE);
}
private InstreamAudioAd ad;
private void initAd()
{
// Enable debug mode
// MyTargetManager.setDebugMode(true);
// Create an instance of InstreamAudioAd
ad = new InstreamAudioAd(YOUR_SLOT_ID, this);
}
private InstreamAudioAd ad;
private void initAd()
{
// Create an instance of InstreamAudioAd
ad = new InstreamAudioAd(YOUR_SLOT_ID, this);
// Install the player
ad.setPlayer(YOUR_PLAYER);
}
float getAdAudioDuration();
float getAdAudioPosition();
void setAdPlayerListener(AdPlayerListener listener);
Context getCurrentContext();
void setVolume(float volume);
void playAdAudio(Uri uri);
void pauseAdAudio();
void resumeAdAudio();
void stopAdAudio();
void onAdAudioStarted();
void onAdAudioPaused();
void onAdAudioResumed();
void onAdAudioStopped();
void onAdAudioError(String message);
void onAdAudioCompleted();
void onVolumeChanged(float volume);
private InstreamAudioAd ad;
private void initAd()
{
// Create an instance of InstreamAudioAd
ad = new InstreamAudioAd(YOUR_SLOT_ID, this);
// Install the event listener
ad.setListener(new InstreamAudioAd.InstreamAudioAdListener()
{
@Override
public void onLoad(InstreamAudioAd ad)
{
// Data uploaded successfully
}
@Override
public void onNoAd(String reason, InstreamAudioAd ad)
{
// Data not received
}
@Override
public void onError(String reason, InstreamAudioAd ad)
{
// An error occurred while playing the ad audio
}
@Override
public void onBannerStart(InstreamAudioAd ad, InstreamAudioAd.InstreamAudioAdBanner banner)
{
// Ad Audio Playback Started
}
@Override
public void onBannerComplete(InstreamAudioAd ad, InstreamAudioAd.InstreamAudioAdBanner banner)
{
// Ad Audio Playback Completed
}
@Override
public void onBannerTimeLeftChange(float timeLeft, float duration, InstreamAudioAd ad)
{
// Called repeatedly during the playback of advertising audio, used to update the timer until the end of the display of advertising audio
}
@Override
public void onComplete(String section, InstreamAudioAd ad)
{
// Playback of all advertising audio in the advertising section is completed.
}
});
// We start data loading
ad.load();
}
// Before you start playing the main audio
ad.startPreroll();
// After playing the main audio
ad.startPostroll();
private InstreamAudioAd ad;
private void initAd()
{
// Create an instance of InstreamAudioAd
ad = new InstreamAudioAd(YOUR_SLOT_ID, this);
// Set the position in the first and fifth seconds of audio
ad.configureMidpoints(videoDuration, new float[]{1f,5f});
// or as a percentage, at 10% and 50% audio
// ad.configureMidpointsPercents(audioDuration, new float[]{10f,50f});
// Install the event listener
ad.setListener(new InstreamAudioAd.InstreamAudioAdListener()
{
@Override
public void onLoad(InstreamAudioAd ad)
{
// Data uploaded successfully
// Array of positions (in seconds) available for playing midroll section
adPositions = ad.getMidPoints();
}
...
});
// We start data loading
ad.load();
}
// Audio played out to the 5th second and for it there is a position in the adPositions array
ad.startMidroll(adPositions[1]);
float getDuration();
boolean isAllowSeek();
boolean isAllowSkip();
boolean isAllowTrackChange();
List<InstreamAdCompanionBanner> getInstreamAdCompanionBanners();
String getAdText();
private void onCompanionAdShow(InstreamAdCompanionBanner companionBanner)
{
ad.handleCompanionShow(companionBanner);
}
private void onCompanionAdClick(InstreamAdCompanionBanner companionBanner)
{
// Processing a click in the context of current activity
ad.handleCompanionClick(companionBanner, context);
// Processing a click in the context that was passed during the creation of the advertising instance
// ad.handleCompanionClick(companionBanner);
}
public void pause()
public void resume()
public void stop()
public void skip()
public void skipBanner()
public void setVolume(float volume)
public void setLoadingTimeout(int loadingTimeout)
private InstreamAudioAd ad;
private void initAd()
{
// Create an instance of InstreamAudioAd
ad = new InstreamAudioAd(YOUR_SLOT_ID, this);
// Receive an instance of additional parameters CustomParams
CustomParams customParams = ad.getCustomParams();
// Set age
customParams.setAge(25);
// Set gender
customParams.setGender(CustomParams.Gender.MALE);
}
@Override
public void onLoad(NativeAd ad)
{
NativePromoBanner banner = ad.getBanner();
// ...
// ...
// List of cards
List<NativePromoCard> cards = banner.getCards();
// An example of filling a visual component
// ...
// ...
if (cards.isEmpty())
{
// Creating MediaAdView
MediaAdView mediaView = NativeViewsFactory.getMediaAdView(context);
adViewLayout.addView(mediaView);
}
else
{
// Creating PromoCardRecyclerView
PromoCardRecyclerView promoCardRecyclerView = NativeViewsFactory.getPromoCardRecyclerView(context);
// Installing the adapter
promoCardRecyclerView.setPromoCardAdapter(new PromoCardRecyclerView.PromoCardAdapter(cards)
{
@Override
public PromoCardView getPromoCardView()
{
return new CardView(context);
}
});
adViewLayout.addView(promoCardRecyclerView);
}
// Registering a visual component
ad.registerView(adViewLayout);
// Adding to the screen
mainLayout.addView(adViewLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
// Example class for displaying one card
private static class CardView extends LinearLayout implements PromoCardView
{
private MediaAdView mediaAdView;
private TextView titleTextView;
private TextView descriptionTextView;
private Button ctaButton;
public CardView(Context context)
{
super(context);
mediaAdView = NativeViewsFactory.getMediaAdView(context);
titleTextView = new TextView(context);
descriptionTextView = new TextView(context);
ctaButton = new Button(context);
addView(mediaAdView);
addView(titleTextView);
addView(descriptionTextView);
addView(ctaButton);
}
@Override
public MediaAdView getMediaAdView()
{
return mediaAdView;
}
@Override
public TextView getTitleTextView()
{
return titleTextView;
}
@Override
public TextView getDescriptionTextView()
{
return descriptionTextView;
}
@Override
public Button getCtaButton()
{
return ctaButton;
}
@Override
public View getView()
{
return this;
}
}