What is an on-screen AD An on-screen AD is an AD that needs to be displayed when an app is launched and before the app’s main screen is displayed. Generally, it is 5S display time. After the advertising display time, the user will automatically enter the application. Users can click the “skip” button to enter the main interface directly.

An example of an open screen AD

Advantages of open screen advertising

Location advantage: Users will see the open screen ads before they enter the App, compared to the in-app ads, and will be forced to view them as long as they are using the App.

Large display area: full screen display of ads, strong visual impact, easy to expose high-quality content, attract users’ attention, enhance user click rate and brand exposure.

When a user first opens an app, the reach is wide and the user’s attention is focused. Therefore, open screen advertising is suitable for advertisers to carry out large-scale brand publicity and product promotion.

Huawei’s AD service allows developers to access six AD slots, including open screen 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 official address: https://github.com/hms-core/h…

Gitee’s official address: https://gitee.com/hms-core/hm…

The Huawei ADS SDK relies on HMS Core (APK) version 4.0.0.300 or 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.

The following four key steps are required to prepare the integration of advertising services before development, which can be referred to the Huawei Developer Alliance documentation

  1. Import HUAWEI ADS SDK
  2. Configure network permissions
  3. Configure Obfuscation Script
  4. To initialize the SDK

1.1 Add SplashView. Add SplashView to the XML layout file.

<? The XML version = "1.0" encoding = "utf-8"? > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".SplashActivity"> <! Android :id="@+id/logo_area" android:layout_width="match_parent" android:layout_height="100dp" android:layout_alignParentBottom="true" android:background="@android:color/white" android:visibility="visible"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="40dp" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="6dp" android:gravity="center" android:orientation="horizontal"> <ImageView android:layout_width="28dp" android:layout_height="28dp" Android :background="@mipmap/ic_launcher" /> <View android:layout_width="0.5dp" android:layout_height="18dp" Android: layout_marginLeft = "12 dp" android: layout_marginRight = "12 dp" android: alpha = "0.1" android:background="@android:color/black" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:alpha="1" android:text="@string/owner" android:textColor="@android:color/black" android:textSize="16sp" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" Android: alpha = "0.5" android: text = "@ string/copyright_info" android: textColor = "@ android: color/black" android:textSize="8sp" /> </LinearLayout> </RelativeLayout> <! - the tail advertising view - > < com. Huawei. HMS. Ads. Splash. SplashView android: id = "@ + id/splash_ad_view" android: layout_width = "match_parent"  android:layout_height="match_parent" android:layout_above="@id/logo" /> </RelativeLayout>

The following sample code shows how to get a SplashView

SplashView splashView = findViewById(R.id.splash_ad_view);

1.2 Modify the default app launch page. The open screen ads are displayed before the main app screen, so you need to change the default app launch page.

Modify AndroidManifest.xml to change the default activity to SplashActivity to display the open screen ads before the app’s main screen loads.

<? The XML version = "1.0" encoding = "utf-8"? > <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.huawei.hms.ads.sdk"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:exported="false" android:screenOrientation="portrait"> </activity> <activity android:name=".SplashActivity" android:exported="true" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> ... </application> </manifest>

Create SplashActivity.java class to get and display open screen ads.

. import android.os.Build; import androidx.appcompat.app.AppCompatActivity; Public class SplashActivity extends AppCompatActivity {// "testQ6ZQ98HECJ"; Private static final String AD_ID = "testQ6ZQ98HECJ "; private static final String AD_ID =" testQ6ZQ98HECJ "; private static final int AD_TIMEOUT = 5000; private static final int MSG_AD_TIMEOUT = 1001; /** * Pause the flag bit. * Set to true when pressing the back button to exit the app to ensure that the main screen of the app will not be pulled up; * When switching to other screens, set it to false to ensure that it can still jump to the main screen of the app when returning to the open screen advertising page from other pages; */ private boolean hasPaused = false; Private Handler timeoutHandler = new Handler(new Handler.Callback()) {@Override public Boolean () {private Handler timeoutHandler = new Handler() handleMessage(@NonNull Message msg) { if (SplashActivity.this.hasWindowFocus()) { jump(); } return false; }}); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); // Get and display the open AD loadAd(); Private void jump() {if (!) {private void jump() {private void jump() {private void jump() {private void jump(); hasPaused) { hasPaused = true; startActivity(new Intent(SplashActivity.this, MainActivity.class)); finish(); }} /** * Set to true when pressing the return key to exit the app, To ensure that the application of the main interface is not pulled up * / @ Override protected void onStop () {/ / remove message queue waiting timeout messages timeoutHandler. RemoveMessages (MSG_AD_TIMEOUT); hasPaused = true; super.onStop(); } /** * is called when you return to the open screen from another page. */ @Override protected void onRestart() {super.onRestart(); hasPaused = false; jump(); } @Override protected void onDestroy() { super.onDestroy();

1.3 Acquisition of advertising. After the SplashView is created, the ads are fetched through the load() method of the SplashView class.

private void loadAd() { int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; AdParam adParam = new AdParam.Builder().build(); SplashView.SplashAdLoadListener splashAdLoadListener = new SplashView.SplashAdLoadListener() { @Override public void OnadLoaded () {// Called when the AD is successful... } @Override public void OnAdFailedToLoad (int ErrorCode) {// Override public void OnAdFailedToLoad (int ErrorCode) {// Override public void OnAdFailedToLoad (int ErrorCode) { } public void Onadelectioneering () {// Override public void Onadelectioneering () {// Override public void Onadelectioneering (); }}; // get splashView splashView splashView = findViewById(R.id.splash_ad_view); / / set the default Slogan splashView. SetSloganResId (R.d rawable. Default_slogan); / / set focus on opening the advertising video class audio type splashView. SetAudioFocusType (AudioFocusType. NOT_GAIN_AUDIO_FOCUS_WHEN_MUTE); Load (AD_ID, orientation, adParam, splashadloadListener); / / delay messages sent to ensure that the advertising display after a timeout, APP page can display properly timeoutHandler. RemoveMessages (MSG_AD_TIMEOUT); timeoutHandler.sendEmptyMessageDelayed(MSG_AD_TIMEOUT, AD_TIMEOUT);

1.4 Monitoring advertising events. Listen for AD display class events by implementing methods in the SplasHadDisplayListener class. For detailed methods, see the SplasHadDisplayListener class in the API documentation.

SplashAdDisplayListener adDisplayListener = new SplashAdDisplayListener() { @Override public void onAdShowed() { // Call... when the AD is displayed. } @Override public void onAdClick() {// Call when the AD is clicked... }}; splashView.setAdDisplayListener(adDisplayListener);

More in-app advertising forms operating guidelines: 1, in-app to add Banner advertising space 2, in-app to add incentive advertising 3, in-app to add native advertising 4, in-app to add screen advertising 5, in-app to add interstitial advertising 6, in-app to add patch advertising

Visit Huawei’s official website for more information

Obtain Huawei Advertising Service Development Guidance Document

Visit the Huawei Developer Alliance website to learn more about it

Get the development guidance document

Address of Huawei Mobile Service Open Source Warehouse: GitHub and Gitee

The original link: https://developer.huawei.com/… Author: Pepper