What is an open screen advertisement

An open screen AD is an AD that needs to be displayed when an app is launched and before it is displayed on the app’s home screen. Generally, the display time is 5s. When the display time is over, the application will be automatically entered. Users can click the skip button to directly enter the main interface.

An example of an open screen advertisement

The advantages of open screen advertising

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

Large display area: full-screen advertising with strong visual impact facilitates the exposure of high-quality content, attracts users’ eyeballs, and enhances users’ click-through rate and brand exposure.

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

Huawei advertising services can help developers access six types of advertising space, including open screen ads. The following article will explain the development steps of the open screen AD in detail. The sample code has been open source in the relevant community, developers are welcome to pay attention to, download and provide valuable advice:

Github official address: github.com/hms-core/hm…

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

The premise condition

HUAWEI Ads SDK depends on HMS Core (APK) 4.0.0.300 or later. If HMS Core (APK) 4.0.0.300 or later is not installed on the device, related interfaces of the HUAWEI Ads SDK cannot be used.

Before developing applications, you need to register as a developer on the Huawei Developer Alliance website and complete the real-name authentication. For details, see Account Registration Authentication.

For details about how to create an application, see Creating a Project and Adding Applications to the Project.

Pre-development preparation

The following four key steps are required to integrate advertising services. For details, see huawei Developer Alliance documents

1. Import the HUAWEI Ads SDK

2. Configure network permissions

3. Configure the obfuscation script

4. Initialize the SDK

1.1 Adding a SplashView.

Add a SplashView to the XML layout file.

Xml code

<? 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"> <! <RelativeLayout 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>Copy the code

The following sample code shows how to get a SplashView

SplashView splashView = findViewById(R.id.splash_ad_view);
Copy the code

1.2 Modifying the Default Application Startup Page.

Open screen ads are displayed before the app’s home screen, so you need to modify the default app startup screen.

Modify androidmanifest.xml to change the default activity to SplashActivity so that the open screen ads are displayed 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>Copy the code

Create a splashactivity. Java class for capturing and displaying open screen ads.

. import android.os.Build; import androidx.appcompat.app.AppCompatActivity; Public class SplashActivity extends Appactivity {// "testQ6zQ98HECj" specifies an advertising slot ID for testing. Private static Final String AD_ID = "testQ6ZQ98HECj "; private static final int AD_TIMEOUT = 5000; private static final int MSG_AD_TIMEOUT = 1001; /** * pause flag bit. * When opening the AD page: * When pressing the back button to exit the application, set the value to true to ensure that the main interface of the application will not be pulled up; * Set the value to false when switching to other screens to ensure that the main screen of the app can still be redirected when returning to the open screen AD page from other pages; */ private boolean hasPaused = false; Private Handler timeoutHandler = new Handler(new handler.callback () {@override public Boolean 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); LoadAd (); } /** * private void jump() {if (! hasPaused) { hasPaused = true; startActivity(new Intent(SplashActivity.this, MainActivity.class)); finish(); }} /** * The value must be set to true when you press the back key to exit the application. 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(); } /** * Override protected void onRestart() {super.onrestart (); hasPaused = false; jump(); } @Override protected void onDestroy() { super.onDestroy();Copy the code

1.3 Advertising acquisition.

Once the SplashView is created, the load() method of the SplashView class gets the ads.

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 () {// When the AD is successfully loaded... } @override public void onAdFailedToLoad(int errorCode) {// Jump (); } @override public void onadelecting () {// Jump (); }}; SplashView SplashView = findViewById(R.id.spash_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); Splashview. 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);Copy the code

1.4 Monitor advertising events.

Listen for AD display class events by implementing methods in the SplashAdDisplayListener class. For details, see the SplashAdDisplayListener class in the API documentation.

SplashAdDisplayListener adDisplayListener = new SplashAdDisplayListener() { @Override public void onAdShowed() { // Ads are displayed when called... } @override public void onAdClick() { }}; splashView.setAdDisplayListener(adDisplayListener);Copy the code

More in-app advertising form operation guide: 1, add Banner advertising space within the app 2, add incentive advertising within the app 3, add native ads within the app 4, add open-screen ads within the app 5, add in-app ads 6, add patch ads within the app

> > visitHuawei advertising Service official websiteTo learn more about it

> > getHuawei Advertising Service Development Guide

> > visitHuawei Developer Alliance official websiteTo learn more about it

> > getDevelopment Guidance document

>> Huawei Mobile Service open source warehouse address:GitHub,Gitee

The original link: developer.huawei.com/consumer/cn…

Original author: Pepper