The express splash ads service is a new traffic monetization solution provided by HUAWEI Ads to improve splash ad experience without requiring you to integrate any SDK.
This codelab will step you through the process of enabling the express splash ads service and correctly displaying an ad in your app.
In this codelab, you will build an empty app and enable the express splash ads service. Your app will:
In this codelab, you will learn how to:
Check method:
To view the HMS Core (APK) version on a device, go to Settings > Apps > Apps and search for HMS Core.
To view the EMUI version on a device, go to Settings > System > About phone.
package com.huawei.hms.ads;
interface ExSplashService {
void enableUserInfo(boolean enable);
}
public final class ExSplashServiceConnection implements ServiceConnection {
private static final String TAG = "ExSplashServiceConnection";
private Context context;
public ExSplashServiceConnection(Context context) {
this.context = context;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "onServiceConnected");
ExSplashService exSplashService = ExSplashService.Stub.asInterface(service);
if (exSplashService != null) {
try {
// true: The user agrees to give consent. false: The user does not agree to give consent.
exSplashService.enableUserInfo(true);
} catch (RemoteException e) {
Log.i(TAG, "enableUserInfo error");
} finally {
context.unbindService(this);
}
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "onServiceDisconnected");
}
}
private boolean bindService(Context context) {
ExSplashServiceConnection serviceConnection = new ExSplashServiceConnection(context);
Intent intent = new Intent("com.huawei.hms.ads.EXSPLASH_SERVICE");
intent.setPackage("com.huawei.hwid");
boolean result = context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
Log.i(TAG, "bindService result: " + result);
return result;
}
During express splash ad display, HUAWEI Ads sends a broadcast message to notify your app. The broadcast action is com.huawei.hms.ads.EXSPLASH_DISPLAYED. Your app can register a broadcast receiver to receive such messages and determine what to do after receiving the messages.
public class ExSplashBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
String action = intent.getAction();
if (action.equals("com.huawei.hms.ads.EXSPLASH_DISPLAYED")) {
// Do your stuff here
}
}
}
IntentFilter filter = new IntentFilter("com.huawei.hms.ads.EXSPLASH_DISPLAYED");
registerReceiver(new ExSplashBroadcastReceiver(), filter);
After running the project, you will see the express splash ad in your app.
Well done. You have successfully completed this codelab and learned how to:
For more information, please click the following links:
Download the demo source code used in this codelab from the following address: