API Reference 2.3 2.x - uc-union/union-ads-sdk-demo GitHub Wiki
UnionAdsSDK is the initialization control class of ad SDK, which is mainly used for the initialization of SDK. It needs to be used in Application.onCreate()
.
Description:
public static void start(Context context)
Instruction: The initialization entrance method of SDK. It needs to be called in Application.onCreate()
Parameter:
Context
: Application Context for Android App
AdRequest
identifies an ad request,which can use AdRequest.Builder
to set the parameter of the AdRequest
and Build the ad request.
Description:
public Builder pub(String pub)
Instruction: Set corresponding pub for ad request
Parameter:
pub
: corresponding pub for requested ad
Return Value: AdRequest.Builder
object
public Builder testDeviceId(String testDeviceId)
Instruction: Set testDeviceId
needed for ad request
Parameter:
testDeviceId
: Corresponding testDeviceId
for third party ad sdk (Facebook, etc.) is exported from Logcat by third party ad sdk
Return Value: AdRequest.Builder
object
public static Builder withOption(AdRequestOption option)
Instruction: Additional parameter needed for setting ad request
options
: Additional parameter needed for setting ad request
Return Value: AdRequest.Builder
object
public AdRequest build()
Instruction: Call to build AdRequest
Return Value: AdRequest
object
To identify an ad, you can load ad content via AdRequest
. We usually use its sub-category, BannerAdView
, InterstitialAd
, NativeAd
.
Description:
void setAdListener(AdListener adListener)
Instruction: Set ad event listener to listen in to the ad loading status, whether ads are clicked or showed and so on
Parameter:
adListener
: Ad loading listener
void loadAd(AdRequest adRequest)
Instruction: Start to load ad
Parameter:
adRequest
: Ad request object, including ad request parameters
Ad event listener, is used to listen in to the loading process and outcome for ads, such as whether ads are successfully loaded or clicked.
Description:
void onAdLoaded(UnionAd ad)
Instruction: Ads are successfully loaded
Parameter:
ad
: Successfully loaded ad object
void onAdClosed(UnionAd ad)
Instruction: Ads are closed
Parameter:
ad
: Closed ads
void onAdShowed(UnionAd ad)
Instruction: Ads are showed
Parameter:
ad
: Showed ads
void onAdClicked(UnionAd ad)
Instruction: Ads are clicked
Parameter:
ad
: Clicked ads
void onAdError(UnionAd ad, AdError error)
Instruction: Ad loading error
Parameter:
ad
: Ads showing error when loading
error
: Ad error object
Ad error message, including error code and detailed error message.
Error codes,
Error code | Corresponding Value | Meaning |
---|---|---|
ERROR_CODE_NETWORK_ERROR | 1000 | Network error |
ERROR_CODE_NO_FILL | 1001 | No match ads |
ERROR_CODE_INTERNAL_ERROR | 1002 | Internal error |
ERROR_CODE_SERVER_ERROR | 1003 | Server error |
ERROR_CODE_REMOTE_CLOSED | 1004 | Remote server is shut down |
Banner ads, please refer to UnionAd for API details.
Interstitial ads, please refer to UnionAd for API details. Note that developers need to invoke show()
when onAdLoaded
is called back.
Native ads, please refer to UnionAd for API details.
When native ads are loaded, native ad data will be returned in the form of NativeAdAssets
. Please refer to NativeAdAssets for more details.
Returned data of native ads, including Title, Detail description, Ad icon and cover picture.
Description:
public String getCallToAction()
Instruction: Get CTA description
Return Value: CTA description
public String getTitle()
Instruction: Get native ad title
Return Value: Ad detailed description
public String getDescription()
Instruction: Get native ad detailed description
Return Value: Ad detailed description
public Image getIcon()
Instruction: Get native ad icon
Return Value: Ad icon Image
object
public Double getRating()
Instruction: Get rating
Return Value: Rating information, which usually corresponds with app ads
public String getPrice()
Instruction: Get price information
Return Value: Ad price information
public Image getCover()
Instruction: Get the first native ad cover image
Return Value: Ad cover Image
object
public List<Image> getCovers()
Instruction: Get all native ad cover image information
Return Value: Ad cover Image
object list
Note:
getCover()
andgetCovers()
are used to receive cover images. If one cover image is returned, then you can get the same cover image information from these two interfaces. If multiple images are returned, you can get one of the images withgetCover()
, and all images withgetCovers()
. Developers usegetCovers()
, when they hope to show multiple covers or that they can choose the most suitable cover from multiple images.
Native ad image data, including url, width, height and so on.
Description:
public String getUrl()
Instruction: Get image's download url
Return Value: Image's download url
public int getWidth()
Instruction: Get image's width
Return Value: Image's witdth(pixel)
public int getHeight()
Instruction: Get image's height
Return Value: Image's height(pixel)
Filter an image set by specified size.
Description:
public static NativeAdAssets.Image filter(List<NativeAdAssets.Image> images,
int widthInDip,
int heightInDip)
Instruction: Filter image set by a specified size(width and height), the width and height parameters should be in the unit of dip. If no image match the specified size, it will return null
or it will return the most matched image.
Parameter:
images
: Image List to be filtered
widthInDip
: Expect image width, in the unit of dip
heightInDip
: Expect image height, in the unit of dip
Use for download and display image.
Description:
public static void downloadImage(NativeAdAssets.Image image,
Delegate delegate)
Instruction: Download an image and notify download result with delegate
Parameter:
image
: Image to download
delegate
: Notify interface for download result
public static void downloadAndDisplayImage(NativeAdAssets.Image image,
final ImageView imageView)
Instruction: download an image and display it on an specified ImageView
Parameter:
image
: Image to download
imageView
: ImageView
to display the downloaed image
public static void downloadAndDisplayImage(NativeAdAssets.Image image,
final ImageView imageView,
final Drawable fallback)
Instruction: Download an image, if download succeed, display it on an specified ImageView
or display fallback
on the specified ImageView` if download failed.
Parameter:
image
: Image to download
imageView
: ImageView
to display the downloaded image
fallback
: Image to display on the ImageView
if download failed