Splash
1、Abstract methods that need to be implemented
- Developers only need to inherit
TPSplashAdapter
and rewrite related methods:- When developers call the
loadAd()
API of TP SDK, theloadCustomAd()
method of the custom Adapter will be called - When developers call the
isReady()
API of TP SDK, theisReady()
method of the custom Adapter will be called - When developers call the
showAd()
API of TP SDK, theisReady()
andshowAd()
methods of the custom Adapter will be called in sequence
- When developers call the
Abstract method | Parameter description | Return value | Function |
---|---|---|---|
loadCustomAd() | context context; userParams local configuration parameters; tpParams server-issued parameters | Context; Map; Map | Used to obtain the parameters issued by the server and the local configuration, and implement the loading logic of custom ads |
showAd() | ----- | ----- | Implement the logic of displaying custom ads. Used to directly pop up the source of activity. |
mAdContainerView | ViewGroup | Implement the logic of displaying custom ads. Used to provide the source of view. Developers can add view directly to the container | |
isReady() | ----- | boolean | Used to determine whether the custom ad is expired before displaying the ad. |
clean() | ----- | ----- | Used to release resources |
getNetworkVersion() | ----- | String | Customized third-party ad version number |
getNetworkName() | ----- | String | Customized third-party ad name |
2、Splash ad event callback
(1) mLoadAdapterListener
implements callback of advertising events
Method | Description |
---|---|
loadAdapterLoadFailed(TPError) | Implements callback of loading failure of advertising events. TPError is described below. |
loadAdapterLoaded(TPBaseAd) | Implements callback of successful loading of advertising events. This type directly passes null |
(2)mShowListener
implements the callback of display ad events
Method | Description |
---|---|
onAdShown() | Implement the display callback of the ad event. |
onAdClosed() | Implement the close callback of the ad event. |
onAdVideoError(TPError) | Implement the display failure callback of the ad event. TPError Parameter 1: error code; Parameter 2: ErrorMessage, error message. |
onAdClicked() | Implement the click callback of the ad event. |
3、Other API descriptions
- TPError
TPError tpError = new TPError(NETWORK_NO_FILL);
tpError.setErrorCode(adError.getErrorCode() +"");
tpError.setErrorMessage(adError.getErrorMessage());
TPError method | Description |
---|---|
setTpErrorCode() | Set the third-party ErrorCode error code. |
setErrorMessage() | Set the third-party ErrorMsg error message. |
NETWORK_NO_FILL | Customized advertising platform NOFILL. |
ADAPTER_CONFIGURATION_ERROR | Customized advertising platform server sent parameter error. |
SHOW_FAILED | Customized advertising platform display failed. |
- Local configuration parameter constants in
loadCustomAd()
Constant | Description |
---|---|
AppKeyManager.GDPR_CONSENT | GDPR, for more information, see Policy Compliance, the same below |
AppKeyManager.KEY_GDPR_CHILD | GDPRChild, GDPR children |
AppKeyManager.KEY_COPPA | COPPA, the United States Children's Online Privacy Protection Act |
AppKeyManager.KEY_CCPA | CCPA, the California Consumer Privacy Act |
4、Demo
/*
* The opening screen type needs to inherit TPSplashAdapter and rewrite the following methods
* loadCustomAd() is used to obtain the parameters sent by the server and locally configured to implement the loading logic of the custom advertising platform
* showAd() implements the logic of displaying the incentive video of the custom advertising platform
* isReady() is used to determine whether the custom ad is expired before displaying the ad
* clean() is used to release resources
* getNetworkVersion() The version number of the custom third-party source
* getNetworkName The name of the custom third-party source
* */
public class AdmobSplashAdapter extends TPSplashAdapter {
public static final String TAG = "AdmobSplashAdapter";
private AppOpenAd mAppOpenAd;
private String placementId;
private AdRequest request;
@Override
public void loadCustomAd(Context context, Map<String, Object> userParams, Map<String, String> tpParams) {
// tpParams Get the fields sent from the server
if (tpParams.size() > 0 && tpParams.containsKey("placemntId")) {
placementId = tpParams.get("placemntId");
} else {
/*
* mLoadAdapterListener is generated synchronously when oadCustomAd is rewritten
* Callback method loadAdapterLoaded: Ad loading is successful
* Callback method loadAdapterLoadFailed: Ad loading fails
* Construct TPError method, ADAPTER_CONFIGURATION_ERROR server sends parameter error
* Method setTpErrorCode sets the third-party ErrorCode error code
* Method setErrorMessage sets the third-party ErrorMsg error message
*
* */
if (mLoadAdapterListener != null) {
mLoadAdapterListener.loadAdapterLoadFailed(new TPError(ADAPTER_CONFIGURATION_ERROR));
}
return;
}
request = new AdRequest.Builder().build();
MobileAds.disableMediationAdapterInitialization(context);
MobileAds.initialize(context, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
Log.i(TAG, "onInitializationComplete: ");
AppOpenAd.load(context, placementId, request, AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT, appOpenAdLoadCallback);
}
});
}
private final AppOpenAd.AppOpenAdLoadCallback appOpenAdLoadCallback = new AppOpenAd.AppOpenAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull AppOpenAd appOpenAd) {
Log.i(TAG, "onAdLoaded: ");
mAppOpenAd = appOpenAd;
if (mLoadAdapterListener != null) {
//Use mLoadAdapterListener to implement the ad event loading success callback
mLoadAdapterListener.loadAdapterLoaded(null);
}
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
Log.i(TAG, "onAdFailedToLoad message: " + loadAdError.getMessage() + ":code:" + loadAdError.getCode());
TPError tpError = new TPError(NETWORK_NO_FILL);
tpError.setErrorCode(String.valueOf(loadAdError.getCode()));
tpError.setErrorMessage(loadAdError.getMessage());
//Use mLoadAdapterListener to achieve the failure of the loading of advertising events
if (mLoadAdapterListener != null)
mLoadAdapterListener.loadAdapterLoadFailed(tpError);
}
};
@Override
public void showAd() {
Activity activity = GlobalTradPlus.getInstance().getActivity();
if (activity == null) {
if (mShowListener != null) {
mShowListener.onAdVideoError(new TPError(ADAPTER_ACTIVITY_ERROR));
}
return;
}
if (mAppOpenAd == null) {
if (mShowListener != null) {
mShowListener.onAdVideoError(new TPError(UNSPECIFIED));
}
return;
}
mAppOpenAd.setFullScreenContentCallback(fullScreenContentCallback);
mAppOpenAd.show(activity);
}
final FullScreenContentCallback fullScreenContentCallback = new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
Log.i(TAG, "onAdDismissedFullScreenContent: ");
//Use mShowListener to implement the closing callback of advertising events
if (mShowListener != null) {
mShowListener.onAdClosed();
}
}
@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
Log.i(TAG, "onAdFailedToShowFullScreenContent msg : " + adError.getMessage() + ":code:" + adError.getCode());
TPError tpError = new TPError(NETWORK_NO_FILL);
tpError.setErrorCode(String.valueOf(adError.getCode()));
tpError.setErrorMessage(adError.getMessage());
if (mLoadAdapterListener != null)
mLoadAdapterListener.loadAdapterLoadFailed(tpError);
}
@Override
public void onAdShowedFullScreenContent() {
Log.i(TAG, "onAdShowedFullScreenContent: ");
//Use mShowListener to implement display callback of advertising events
if (mShowListener != null) {
mShowListener.onAdShown();
}
}
};
@Override
public void clean() {
// Release resources
if (mAppOpenAd != null) {
mAppOpenAd.setFullScreenContentCallback(null);
mAppOpenAd = null;
}
}
@Override
public boolean isReady() {
// Used to determine whether the advertisement has expired
return true;
}
@Override
public String getNetworkName() {
return "Admob";
}
@Override
public String getNetworkVersion() {
return MobileAds.getVersionString();
}
}