What is a patch AD
A patch advertisement is a video or picture advertisement inserted during the playing of a video. The video advertisement is usually 15s long. You can click the skip button to enter the video playing interface directly, or automatically enter the video playing interface after the advertisement is displayed.
Advantages of patch advertising
Compared with other forms of advertising space, patch advertising has a long history and is currently a more common form of online video advertising. As long as the user watches the video, the patch advertisement will appear, so the play volume of the patch advertisement is large and the touch rate is high.
Huawei’s AD service enables developers to access six types of AD space, including patch ads. The following articles will explain in detail the development steps of an on-screen AD. The sample code has been open source in relevant communities, developers are welcome to pay attention to, download and provide valuable comments:
GitHub’s official address: https://github.com/hms-core/h…
Gitee’s official address: https://gitee.com/hms-core/hm…
The premise condition
Huawei ADS SDK relies on HMS Core (APK) version 4.0.0.300 and above. If version 4.0.0.300 or above of HMS Core (APK) is not installed on the device, the relevant interface of HUAWEI ADS SDK cannot be used.
Before developing the application, you need to register as a developer on the website of Huawei Developer Union and complete the real-name authentication. Please refer to the account registration authentication for specific methods.
See Creating a project and adding an application to a project to complete the creation of the application.
Pre-development preparation
The integration of advertising services requires the following four key steps, which can be referred to the Huawei Developer Alliance documentation
- Import HUAWEI ADS SDK
- Configure network permissions
- Configure Obfuscation Script
- To initialize the SDK
Key development steps
1.1 Create InstreamadLoader.
The InstreamadLoader class provides the InstreamadLoader.Builder class, which can be used to set an AD spot ID, set custom options, and create an InstreamadLoader object.
"Java" // "testy3cglm3pj0" is the AD space ID for testing, InstreamadLoader. Builder Builder = new InstreamadLoader. Builder(context, "testy3cglm3pj0"); InstreamadLoader adLoader = Builder. setTotalDuration(TotalDuration) // Set the maximum number of items returned by the patch. .setInstreamAdLoadListener(new InstreamAdLoadListener() { @Override public void onAdLoaded(List<InstreamAd> ads) { // After the AD is successful, call... } @Override public void onadFailed (int errorCode) {// Override public void onadFailed (int errorCode) {// Override public void onadFailed (int errorCode) { } }).build();
When the AD is retrieved successfully, the SDK calls the list of InStreamAd objects returned by the onadLoaded () method of the InStreamAdloadListener.
When the fetch fails, the SDK calls the onadFailed () method of the InstreamAdLoadListener.
1.2 Acquisition of advertising.
InstreamadLoader provides the loadAd() method to fetch ads.
InstreamAdLoader.loadAd(new AdParam.Builder().build());
After calling loadAd(), the SDK makes a success or failure callback to the added listener method.
1.3 Display patch advertisements.
To display an AD in the listener callback method after acquiring an AD, you need to display the “why see this AD” icon “I” or the “no longer show this AD” icon “x” in the corner of each AD view, and you must display the AD logo.
Here are the steps to display a patch AD:
Define the post advertising layout.
You need to define a layout to display the AD material in the InStreamAd list.
<RelativeLayout android:id="@+id/instream_ad_container" android:layout_width="match_parent" android:layout_height="200dp" android:visibility="gone"> <! - patch advertising view - > < com. Huawei. HMS. Ads. Instreamad. InstreamView android: id = "@ + id/instream_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <! Android :id="@+id/instream_skip" android:layout_width="wrap_content" android:id="@+id/instream_skip" android:layout_height="wrap_content" ... / > <! Android :id="@+id/instream_count_down" android:layout_width="wrap_content" android:layout_width="wrap_content" android:layout_height="wrap_content" ... / > <! Android :id="@+id/instream_ad_flag" android:layout_width="wrap_content" android:id="@+id/instream_ad_flag" android:layout_height="wrap_content" ... / > <! > <ImageView android:id="@+id/instream_why_this_ad" android:layout_width="14dp" android:layout_height="14dp" ... / > <! Android :id="@+id/instream_call_to_action" android:layout_width="wrap_content" android:id="@+id/instream_call_to_action" android:layout_height="wrap_content" ... /> </RelativeLayout>
Register ads to the ads view.
Once you have a list of InStreamad objects, you need to register your ads in the Ads view. instreamView.setInstreamAds(ads);
Monitor AD status.
Patch advertising provides InstreamMediaStateListener, InstreamMediaChangeListener and MediaMuteListener to monitor patch advertising state.
instreamView.setInstreamMediaChangeListener(new InstreamMediaChangeListener(){ @Override public void OnSegmentMediaRange (InstreamAd AD) {// Ad media toggles... }}); instreamView.setInstreamMediaStateListener(new InstreamMediaStateListener() { @Override public void onMediaProgress(int Percent, int playTime) {// Percent, int playTime; } @Override public void onMediaStart(int playTime) {// Override public void onMediaStart(int playTime) {// Override public void onMediaStart(int playTime) { } @Override public void onMediaPause(int playTime) {// Pause... } @ Override public void onMediaStop (int playTime) {/ / play stop... } @Override public void onMediaCompletion(int playTime) {// The playback is complete... } @ Override public void onMediaError (int playTime, int errorCode, int extra) {/ / play wrong... }}); InstreamView. SetMediaMuteListener (new MediaMuteListener () {@ Override public void onMute () {/ / patch advertising mute... } public void onUnmute() {// Override public void onUnmute() { }});
Destroy advertisements.
When the display of the patch advertisement ends, the view of the patch advertisement should be destroyed. instreamView.destroy();
More in-app advertising how-to guidelines:
1. Add Banner advertising space in the app
2. Add in-app motivational ads
3. Add native ads in your app
4. Add screen ads in the app
5. Add in-app interstitials
6. Add patch ads in the app
Visit the official website of Huawei advertising service to obtain the guidance document of Huawei advertising service development
For more information, please visit the official website and development guidance document of Huawei Developer Alliance
Address of Huawei Mobile Service Open Source Warehouse: GitHub and Gitee
The original link: https://developer.huawei.com/… Author: Pepper