test-package-npme
v0.0.0
Published
TestPackage
Downloads
2
Readme
React-Native HMS Ads
Contents
- 1. Introduction
- 2. Installation Guide
- 3. API Reference
- 4. Configuration and Description
- 5. Sample Project
- 6. Questions or Issues
- 7. Licensing and Terms
1. Introduction
This module enables communication between Huawei Ads SDK and React Native platform. It exposes all functionality provided by Huawei Ads SDK.
2. Installation Guide
Integrating React Native Ads Plugin
Step 1: Sign in to AppGallery Connect and select My projects.
Step 2: Find your app project, and click the desired app name.
Step 3: Go to Project Setting > General information. In the App information section, click agconnect-service.json to download the configuration file.
Step 4: Create a React Native project if you do not have one.
Step 5: Copy the agconnect-service.json file to the android/app directory of your React Native project.
Step 6: Copy the signature file that generated in Generating a Signing Certificate section, to the android/app directory of your React Native project.
Step 7: Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the React Native project.
Step 8: Open the build.gradle file in the android directory of your React Native project.
- Go to buildscript then configure the Maven repository address and agconnect plugin for the HMS SDK.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
/*
* <Other dependencies>
*/
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
- Go to allprojects then configure the Maven repository address for the HMS SDK.
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
Step 9: Set your package name in defaultConfig > applicationId and set minSdkVersion to 19 or higher.
- Package name must match with the package_name entry in agconnect-services.json file.
defaultConfig {
applicationId "<package_name>"
minSdkVersion {{your_min version}}
/*
* <Other configurations>
*/
}
Copy the signature file that generated in Generating a Signing Certificate to android/app directory.
Configure the signature in android according to the signature file information and configure Obfuscation Scripts.
android {
/*
* <Other configurations>
*/
signingConfigs {
config {
storeFile file('<keystore_file>.jks')
storePassword '<keystore_password>'
keyAlias '<key_alias>'
keyPassword '<key_password>'
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
...
}
}
}
Using NPM
Step 1: Download plugin using command below.
npm i @hmscore/react-native-hms-ads
Step 2: Run your project.
- Run the following command to the project directory.
react-native run-android
Download Link
To integrate the plugin, follow the steps below:
Step 1: Download the React Native Ads Plugin and place react-native-hms-ads under node_modules/@hmscore of your React Native project, as shown in the directory tree below.
project.dir
|_ node_modules
|_ @hmscore
|_ react-native-hms-ads
...
Step 2: Open build.gradle file which is located under project.dir > android > app directory.
- Configure build dependencies.
buildscript {
...
dependencies {
/*
* <Other dependencies>
*/
implementation project(":react-native-hms-ads")
...
}
}
Step 3: Add the following lines to the android/settings.gradle file in your project:
include ':app'
include ':react-native-hms-ads'
project(':react-native-hms-ads').projectDir = new File(rootProject.projectDir, '../node_modules/@hmscore/react-native-hms-ads/android')
Step 4: Open the your application class and add the RNHMSAdsPackage
Import the following classes to the MainApplication.java file of your project.import com.huawei.hms.rn.ads.RNHMSAdsPackage.
Then, add the RNHMSAdsPackage to your getPackages method. In the end, your file will be similar to the following:
import com.huawei.hms.rn.ads.RNHMSAdsPackage;
@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new RNHMSAdsPackage());
return packages;
}
...
Step 5: Run your project.
- Run the following command to the project directory.
react-native run-android
3. API Reference
Components
HMSBanner
Banner ad component
Simple Call Example
import {
HMSBanner,
BannerAdSizes,
} from '@hmscore/react-native-hms-ads';
<HMSBanner
style={{height: 100}}
bannerAdSize={{
bannerAdSize:BannerAdSizes.B_320_100,
}}
adId="testw6vs28auh3"
/>
Properties
| Prop | Type | Definition |
| ---------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| bannerAdSize
| BannerAdSizeProp
| The object parameter that has banner size information. It can have width information if needed. |
| adId
| string
| Ad slot id. |
| adParam
| AdParam
| Ad request parameter. |
| onAdLoaded
| function
| The function to handle the event when ad loads. It gets event information object as argument which has nativeEvent
as key and BannerResult
object as value. |
| onAdFailed
| function
| The function to handle the event when ad fails to load. It gets event information object as argument which has nativeEvent
as key and Error
object as value. |
| onAdOpened
| function
| The function to handle the event when ad is opened. |
| onAdClicked
| function
| The function to handle the event when ad is clicked. |
| onAdClosed
| function
| The function to handle the event when ad is closed. |
| onAdImpression
| function
| The function to handle the event when ad impression is detected. |
| onAdLeave
| function
| The function to handle the event when user leaves the app. |
BannerAdSizeProp
| Parameter | Type | Definition |
| -------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| bannerAdSize
| string
| Banner ad sizes. Check BannerAdSizes
for possible values. |
| width
| integer
| If banner ad size is 'portrait'
, or 'landscape'
, or 'currentDirection'
, this will be needed to set the width of the banner . |
Commands
Commands can be used with component references which are created with ref prop of React component.
Call Example
import {
HMSBanner,
BannerAdSizes,
} from '@hmscore/react-native-hms-ads';
// Example for commands
let adBannerElement;
// ...
<HMSBanner
style={{height: 100}}
bannerAdSize={{
bannerAdSize:BannerAdSizes.B_320_100,
}}
adId="testw6vs28auh3"
ref={(el) => (adBannerElement = el)}
/>
a) loadAd()
Loads banner.
Call Example
adBannerElement.loadAd()
b) setRefresh()
Sets a rotation interval for banner ads. Input is rotation interval, in seconds. It should range from 30 to 120.
Parameters
| Name | Type | Description |
| -------- | -------- | --------------------------------------------------------------- |
| interval | number
| Rotation interval, in seconds. It should range from 30 to 120 . |
Call Example
adBannerElement.setRefresh(60)
c) pause()
Pauses any additional processing related to ad.
Call Example
adBannerElement.pause()
f) resume()
Resumes ad after the pause() method is called last time.
Call Example
adBannerElement.resume()
e) destroy()
Destroys ad.
Call Example
adBannerElement.destroy()
Complex Call Example
import {
HMSBanner,
BannerAdSizes,
ContentClassification,
Gender,
NonPersonalizedAd,
TagForChild,
UnderAge,
} from '@hmscore/react-native-hms-ads';
<HMSBanner
style={{height: 100}}
bannerAdSize={{
bannerAdSize:BannerAdSizes.B_PORTRAIT,
width: 300,
}}
adId="testw6vs28auh3"
adParam={{
adContentClassification:
ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
gender: Gender.UNKNOWN,
nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
tagForChildProtection:
TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
}}
onAdLoaded={(e) => {
console.log('HMSBanner onAdLoaded', e.nativeEvent);
}}
onAdFailed={(e) => {
console.warn('HMSBanner onAdFailed', e.nativeEvent);
}}
onAdOpened={(e) => console.log('HMSBanner onAdOpened')}
onAdClicked={(e) => console.log('HMSBanner onAdClicked')}
onAdClosed={(e) => console.log('HMSBanner onAdClosed')}
onAdImpression={(e) => console.log('HMSBanner onAdImpression')}
onAdLeave={(e) => console.log('HMSBanner onAdLeave')}
/>
HMSNative
Native ad component
Simple Call Example
import {
HMSNative,
NativeMediaTypes,
} from '@hmscore/react-native-hms-ads';
<HMSNative
style={{ height: 322 }}
displayForm={{
mediaType: NativeMediaTypes.VIDEO,
adId: 'testy63txaom86'
}}
/>
Properties
| Parameter | Type | Definition |
| ------------------ | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| displayForm
| DisplayFormProp
| The object parameter that has ad slot id and media type information. |
| adParam
| AdParam
| Ad request parameter. |
| nativeConfig
| NativeAdConfiguration
| Native ad configuration parameter. |
| viewOptions
| ViewOptionsProp
| View options parameter. |
| onNativeAdLoaded
| function
| The function to handle the event when ad loads. It gets event information object as argument which has nativeEvent
as key and NativeResult
object as value. |
| onAdDisliked
| function
| The function to handle the event when ad is disliked. |
| onAdFailed
| function
| The function to handle the event when ad fails to load. It gets event information object as argument which has nativeEvent
as key and Error
object as value. |
| onAdClicked
| function
| The function to handle the event when ad is clicked. |
| onAdImpression
| function
| The function to handle the event when ad impression is detected. |
| onVideoStart
| function
| The function to handle the event when ad video starts playing. |
| onVideoPlay
| function
| The function to handle the event when ad video plays. |
| onVideoEnd
| function
| The function to handle the event when ad video ends. |
DisplayFormProp
| Parameter | Type | Definition |
| ----------- | -------- | ----------------------------------------------------------------------------------------------- |
| mediaType
| string
| Media type of the native ad. Check NativeMediaTypes
for possible values. |
| adId
| string
| Ad slot id. |
ViewOptionsProp
| Parameter | Type | Definition |
| ---------------------- | ----------------------------- | ------------------------------------------------------------------------- |
| showMediaContent
| boolean
| The option for showing media content. |
| mediaImageScaleType
| integer
| The image scale type. Check ScaleType
for possible values |
| adSourceTextStyle
| AdTextStyle
| The style of ad source. |
| adFlagTextStyle
| AdTextStyle
| The style of ad flag. |
| titleTextStyle
| AdTextStyle
| The style of ad title. |
| descriptionTextStyle
| AdTextStyle
| The style of ad description. |
| callToActionStyle
| AdTextStyle
| The style of ad call-to-action button. |
Commands
Commands can be used with component references which are created with ref prop of React component.
Call Example
import {
HMSNative,
NativeMediaTypes,
} from '@hmscore/react-native-hms-ads';
let adNativeElement;
// ...
<HMSNative
style={{height: 100}}
displayForm={{
mediaType:NativeMediaTypes.VIDEO,
adId:'testy63txaom86',
}}
ref={(el) => (adNativeElement = el)}
/>
a) loadAd()
Loads native ad.
Call Example
adNativeElement.loadAd()
b) dislikeAd()
Dislikes ad with description.
Parameters
| Name | Type | Description |
| ------ | -------- | ------------------------------- |
| reason | string
| Reason why the ad is disliked . |
Call Example
adNativeElement.dislikeAd('Just dont like it')
c) destroy()
Destroys ad.
Call Example
adNativeElement.destroy()
d) gotoWhyThisAdPage()
Goes to the page explaining why an ad is displayed.
Call Example
adNativeElement.gotoWhyThisAdPage()
e) setAllowCustomClick()
Enables custom tap gestures.
Call Example
adNativeElement.setAllowCustomClick()
f) recordClickEvent()
Reports a custom tap gesture.
Call Example
adNativeElement.recordClickEvent()
g) recordImpressionEvent()
Reports an ad impression.
Parameters
| Name | Type | Description |
| ---------- | -------- | ------------------------ |
| impression | object
| Custom impression data . |
Call Example
adNativeElement.recordImpressionEvent({myKey: 'myValue', yourKey:{ cool: true}})
Complex Call Example
import {
HMSNative,
NativeMediaTypes,
ContentClassification,
Gender,
NonPersonalizedAd,
TagForChild,
UnderAge,
ChoicesPosition,
Direction,
AudioFocusType,
ScaleType
} from '@hmscore/react-native-hms-ads';
<HMSNative
style={{height: 322}}
displayForm={{
mediaType:NativeMediaTypes.VIDEO,
adId:'testy63txaom86',
}}
adParam={{
adContentClassification:
ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
gender: Gender.UNKNOWN,
nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
tagForChildProtection:
TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
}}
nativeConfig={{
choicesPosition: ChoicesPosition.BOTTOM_RIGHT,
mediaDirection: Direction.ANY,
videoConfiguration: {
audioFocusType: AudioFocusType.NOT_GAIN_AUDIO_FOCUS_ALL,
startMuted: true,
},
}}
viewOptions={{
showMediaContent: false,
mediaImageScaleType: ScaleType.FIT_CENTER,
adSourceTextStyle: {color: 'red'},
adFlagTextStyle: {backgroundColor: 'red', fontSize: 10},
titleTextStyle: {color: 'red'},
descriptionTextStyle: {visibility: false},
callToActionStyle: {color: 'black', fontSize: 12},
}}
onNativeAdLoaded={(e) => {
console.log('HMSNative onNativeAdLoaded', e.nativeEvent);
}}
onAdDisliked={(e) => console.log('HMSNative onAdDisliked')}
onAdFailed={(e) => {
console.warn('HMSNative onAdFailed', e.nativeEvent);
}}
onAdClicked={(e) => console.log('HMSNative onAdClicked')}
onAdImpression={(e) => console.log('HMSNative onAdImpression')}
onVideoStart={(e) => console.log('HMSNative onVideoStart')}
onVideoPlay={(e) => console.log('HMSNative onVideoPlay')}
onVideoEnd={(e) => console.log('HMSNative onVideoEnd')}
ref={(el) => {
adNativeElement = el;
}}
/>
Modules
HMSAds
HMSOaid
HMSReward
HMSInterstitial
HMSSplash
Methods
Events
HMSInstallReferrer
Methods
HMSAds.init()
Initializes the HUAWEI Ads SDK. The function returns a promise that resolves a string 'Hw Ads Initialized'.
Return Type
| Type | Description | | --------------- | ------------------ | | Promise | Hw Ads Initialized |
Call Example
import HMSAds from '@hmscore/react-native-hms-ads';
HMSAds.init()
.then((result) => console.log('HMSAds init, result:', result))
HMSAds.getSDKVersion()
Obtains the version number of the HUAWEI Ads SDK. The function returns a promise that resolves a string of the version number.
Return Type
| Type | Description | | --------------- | ----------- | | Promise | SDK Version |
Call Example
import HMSAds from '@hmscore/react-native-hms-ads';
HMSAds.getSDKVersion()
.then((result) => console.log('HMS getSDKVersion, result:', result));
HMSAds.setRequestOptions()
Provides the global ad request configuration. The function returns a promise that resolves a RequestOptions
object.
Parameters
| Name | Type | Description |
| -------------- | ----------------------------------- | ------------------- |
| requestOptions | RequestOptions
| Ad request options. |
Return Type
| Type | Description |
| -------------------------------------------- | ------------------- |
| Promise<RequestOptions
> | Ad request options. |
Call Example
import HMSAds, {
ContentClassification,
NonPersonalizedAd,
TagForChild,
UnderAge,
} from '@hmscore/react-native-hms-ads';
HMSAds.setRequestOptions({
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
nonPersonalizedAd: NonPersonalizedAd.ALLOW_ALL,
adContentClassification:
ContentClassification.AD_CONTENT_CLASSIFICATION_A,
tagForChildProtection:
TagForChild.TAG_FOR_CHILD_PROTECTION_UNSPECIFIED,
appCountry: "TR",
appLang: "tr",
})
.then((result) => console.log('HMS setRequestOptions, result:', result))
HMSAds.getRequestOptions()
Obtains the global request configuration. The function returns a promise that resolves a RequestOptions
object.
Return Type
| Type | Description |
| ------------------------------------- | ------------------- |
| <RequestOptions
> | Ad request options. |
Call Example
import HMSAds from '@hmscore/react-native-hms-ads';
HMSAds.getRequestOptions()
.then((result) => console.log('HMS getRequestOptions, result:', result))
HMSAds.setConsent()
Provides ad consent configuration. The function returns a promise that resolves a ConsentResult
object.
Parameters
| Name | Type | Description |
| ------------- | --------------------------------- | ----------------------------------- |
| consentResult | ConsentResult
| Consent information from api result |
Return Type
| Type | Description |
| ------------------------------------------ | ----------------------------------- |
| Promise<ConsentResult
> | Consent information from api result |
Call Example
import HMSAds, {
ConsentStatus,
DebugNeedConsent,
UnderAge,
} from '@hmscore/react-native-hms-ads';
HMSAds.setConsent({
consentStatus: ConsentStatus.NON_PERSONALIZED,
debugNeedConsent: DebugNeedConsent.DEBUG_NEED_CONSENT,
underAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED,
// testDeviceId: '********',
})
.then((result) => console.log('HMS setConsent, result:', result))
.catch((e) => console.warn('HMS setConsent, error:', e))
HMSAds.checkConsent()
Obtains ad consent configuration. The function returns a promise that resolves a ConsentResult
object.
Return Type
| Type | Description |
| ------------------------------------------ | ----------------------------------- |
| Promsie<ConsentResult
> | Consent information from api result |
Call Example
import HMSAds from '@hmscore/react-native-hms-ads';
HMSAds.checkConsent()
.then((result) => console.log('HMS checkConsent, result:', result))
.catch((e) => console.log('HMS checkConsent, error:', e))
HMSOaid.getAdvertisingIdInfo()
Obtains the OAID and 'Limit ad tracking' setting. The string argument should be one of values of CallMode
. The function returns a promise that resolves a AdvertisingIdClientInfo
object.
Parameters
| Name | Type | Description | | -------- | ------ | -------------------------------------------------------------------------------------------------------------------- | | callMode | string | Option for functions that can use Huawei SDK or Aidl service. |
Return Type
| Type | Description |
| -------------------------------------------------------------- | ------------------------------------- |
| Promise<AdvertisingIdClientInfo
> | Information about advertised clients. |
Call Example
import {HMSOaid, CallMode} from '@hmscore/react-native-hms-ads';
let callMode = CallMode.SDK;
HMSOaid.getAdvertisingIdInfo(callMode)
.then((result) => console.log('HMSOaid getAdvertisingIdInfo, result:', result))
.catch((e) => console.log('HMSOaid getAdvertisingIdInfo, error:', e))
HMSOaid.verifyAdvertisingId()
Verifies the OAID and 'Limit ad tracking' setting. The function returns a promise that resolves a boolean showing the verification result.
Parameters
| Name | Type | Description |
| ----------------------- | ----------------------------------------------------- | ------------------------------------- |
| advertisingIdClientInfo | AdvertisingIdClientInfo
| Information about advertised clients. |
Return Type
| Type | Description |
| -------------------------------------------------------------- | ------------------------------------- |
| Promise<AdvertisingIdClientInfo
> | Information about advertised clients. |
Call Example
import {HMSOaid} from '@hmscore/react-native-hms-ads';
// should use information obtained from 'getAdvertisingIdInfo()' function
let advertisingInfo = {
id: "01234567-89abc-defe-dcba-987654321012",
isLimitAdTrackingEnabled: false
}
HMSOaid.verifyAdvertisingId(advertisingInfo)
.then((result) => console.log('HMSOaid verifyAdvertisingId, result:', result))
.catch((e) => console.warn('HMSOaid verifyAdvertisingId, error:', e))
HMSReward.setAdId()
Sets ad slot id.
Parameters
| Name | Type | Description |
| ------ | -------- | ----------- |
| slotId | string
| Slot id. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.setAdId("testx9dtjwj8hp"); // video ad
HMSReward.setUserId()
Sets user id.
Parameters
| Name | Type | Description |
| ------ | -------- | ----------- |
| userId | string
| User id. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.setUserId("HMS User");
HMSReward.setData()
Sets custom data in string.
Parameters
| Name | Type | Description |
| ---- | -------- | ---------------------- |
| data | string
| Custom data in string. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.setData("HMS Data");
HMSReward.setVerifyConfig()
Sets server-side verification parameters.
Parameters
| Name | Type | Description |
| ------------ | ------------------------------- | ----------------------------------- |
| verifyConfig | VerifyConfig
| Server-side verification parameter. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.setVerifyConfig({userId: 'userxxxxx', data: 'dataxxxx'});
HMSReward.setAdParam()
Sets parameters of ad request.
Parameters
| Name | Type | Description |
| ------- | --------------------- | ---------------------- |
| adParam | AdParam
| Ad request parameters. |
Call Example
import {HMSReward, ContentClassification, UnderAge} from '@hmscore/react-native-hms-ads';
HMSReward.setAdParam({
adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});
HMSReward.pause()
Pauses the ad.
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.pause();
HMSReward.resume()
Resumes the ad.
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.resume();
HMSReward.loadAd()
Requests ad.
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.loadAd();
HMSReward.show()
Displays ad.
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.show();
HMSReward.isLoaded()
Checks whether ad is successfully loaded. The function returns a promise that resolves a boolean indicating whether the ad is loaded or not.
Return Type
| Type | Description |
| ------------------ | ----------------------------------------- |
| Promise<boolean
> | Indicates whether the ad is loaded or not |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.isLoaded()
.then((result) => console.log('HMSReward isLoaded, result:', result))
HMSReward.allListenersRemove()
Remove all listeners for events of HMSReward.
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.allListenersRemove();
HMSSplash.setAdId()
Sets ad slot id.
Parameters
| Name | Type | Description |
| ------ | -------- | ----------- |
| slotId | string
| Slot id. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.setAdId("testd7c5cewoj6"); // video ad
HMSSplash.setLogoText()
Sets logo text.
Parameters
| Name | Type | Description |
| -------- | -------- | ----------- |
| logoText | string
| Logo text. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.setLogoText("HMS Sample");
HMSSplash.setCopyrightText()
Sets copyright text.
Parameters
| Name | Type | Description |
| ------------- | -------- | --------------- |
| copyRightText | string
| Copyright text. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.setCopyrightText("Copyright HMS");
HMSSplash.setOrientation()
Sets screen orientation.
Parameters
| Name | Type | Description |
| ----------------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| screenOrientation | number
| Sets screen orientation. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.setOrientation(1);
HMSSplash.setSloganResource()
Sets default app launch image in portrait mode, which is displayed before a splash ad is displayed.
Parameters
| Name | Type | Description |
| -------------- | -------- | ------------------------------------------------------- |
| sloganResource | string
| text that is displayed before a splash ad is displayed. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setSloganResource("file_name_without_extension");
HMSSplash.setWideSloganResource()
Sets default app launch image in landscape mode, which is displayed before a splash ad is displayed.
Parameters
| Name | Type | Description |
| ------------------ | -------- | ------------------------------------------------------- |
| wideSloganResource | string
| Text that is displayed before a splash ad is displayed. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setWideSloganResource("file_name_without_extension");
HMSSplash.setLogoResource()
Sets app logo.
Parameters
| Name | Type | Description |
| ------- | -------- | ------------------------------------ |
| appLogo | string
| App logo file path without extension |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
// file_name_without_extension.png added to res/drawable or res/mipmap
HMSSplash.setLogoResource("file_name_without_extension");
HMSSplash.setMediaNameResource()
Sets app text resource.
Parameters
| Name | Type | Description |
| ------------ | -------- | ----------------- |
| textResource | string
| app text resource |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
// <string name="media_name">HUAWEI Ads</string> line inserted to strings.xml
HMSSplash.setMediaNameResource("media_name");
HMSSplash.setAudioFocusType()
Sets the audio focus preemption policy for a video splash ad.
Parameters
| Name | Type | Description |
| -------------- | -------- | ------------------------------------------------------------------------------ |
| audioFocusType | number
| Number value that determines the the audio focus preemption policy for a video |
Call Example
import {HMSSplash, AudioFocusType} from '@hmscore/react-native-hms-ads';
HMSSplash.setAudioFocusType(AudioFocusType.GAIN_AUDIO_FOCUS_ALL);
HMSSplash.setAdParam()
Sets parameters of ad request.
Parameters
| Name | Type | Description |
| ------- | --------------------- | ---------------------- |
| adParam | AdParam
| Ad request parameters. |
Call Example
import {HMSSplash, ContentClassification, UnderAge} from '@hmscore/react-native-hms-ads';
HMSSplash.setAdParam({
adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});
HMSSplash.pause()
Pauses ad.
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.pause();
HMSSplash.resume()
Resumes ad.
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.resume();
HMSSplash.destroy()
Destroys ad.
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.destroy();
HMSSplash.show()
Shows ad.
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.show();
HMSSplash.isLoaded()
Checks whether a splash ad has been loaded.
Return Type
| Type | Description |
| ------------------ | -------------------------------------- |
| Promise<boolean
> | Indicates whether ad is loaded or not. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.isLoaded()
.then((result) => console.log('HMSSplash isLoaded, result:', result))
HMSSplash.isLoading()
Checks whether a splash ad is being loaded.
Return Type
| Type | Description |
| ------------------ | --------------------------------------- |
| Promise<boolean
> | Indicates whether ad is loading or not. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.isLoading()
.then((result) => console.log('HMSSplash isLoading, result:', result))
HMSSplash.allListenersRemove()
Remove all listeners for events of HMSSplash.
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.allListenersRemove();
HMSInterstitial.setAdId()
Sets ad slot id.
Parameters
| Name | Type | Description |
| ------ | -------- | ----------- |
| slotId | string
| Ad slot id. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.setAdId("testb4znbuh3n2"); // video ad
HMSInterstitial.setAdParam()
Sets parameters of ad request.
Parameters
| Name | Type | Description |
| ------- | --------------------- | ---------------------- |
| adParam | AdParam
| Ad request parameters. |
Call Example
import {HMSInterstitial, ContentClassification, UnderAge} from '@hmscore/react-native-hms-ads';
HMSInterstitial.setAdParam({
adContentClassification: ContentClassification.AD_CONTENT_CLASSIFICATION_UNKOWN,
tagForUnderAgeOfPromise: UnderAge.PROMISE_UNSPECIFIED
});
HMSInterstitial.loadAd()
Initiates a request to load an ad.
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.loadAd();
HMSInterstitial.show()
Displays an interstitial ad.
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.show();
HMSInterstitial.isLoaded()
Checks whether ad loading is complete.
Return Type
| Type | Description |
| ------------------ | -------------------------------------- |
| Promise<boolean
> | Indicates whether ad is loaded or not. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.isLoaded()
.then((result) => console.log('HMSInterstitial isLoaded, result:', result))
HMSInterstitial.allListenersRemove()
Remove all listeners for events of HMSInterstitial.
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.allListenersRemove();
HMSInstallReferrer.startConnection()
Starts to connect to the install referrer service. The first string argument should be one of values of CallMode
. And the boolean argument indicates test mode. The last string argument is the name of the package that the service receives information about. The function returns a promise that resolves a boolean indicating whether the service is successfully connected.
Parameters
| Name | Type | Description |
| ----------- | --------- | -------------------------------------------------------------------------------------------------------------------- |
| callMode | string
| Option for functions that can use Huawei SDK or Aidl service. |
| testMode | boolean
| Indicates test mode. |
| packageName | string
| Name of the package that the service receives information about. |
Return Type
| Type | Description |
| ------------------ | -------------------------------------------------------- |
| Promise<boolean
> | Indicates whether the service is successfully connected. |
Call Example
import {HMSInstallReferrer, CallMode} from '@hmscore/react-native-hms-ads';
let callMode = CallMode.SDK;
let isTest = 'true';
let pkgName = 'com.huawei.rnhmsadsdemo'; // your app package name
HMSInstallReferrer.startConnection(callMode, isTest, pkgName)
.then((result) => console.log('HMSInstallReferrer startConnection, result:', result))
.catch((e) => console.warn('HMSInstallReferrer startConnection, error:', e));
HMSInstallReferrer.endConnection()
Ends the service connection and releases all occupied resources.
Return Type
| Type | Description | | ------------- | ---------------------------------------------------- | | Promise | Promise that resolves if the operation is successful |
Call Example
import {HMSInstallReferrer} from '@hmscore/react-native-hms-ads';
HMSInstallReferrer.endConnection()
.then(() => console.log('HMSInstallReferrer endConnection'))
.catch((e) => console.warn('HMSInstallReferrer endConnection, error:', e));
HMSInstallReferrer.getReferrerDetails()
Obtains install referrer information.
Return Type
| Type | Description | | -------------------------------------------- | ------------------------------------------- | | Promise<ReferrerDetails> | Describes the install referrer information. |
Call Example
import {HMSInstallReferrer} from '@hmscore/react-native-hms-ads';
HMSInstallReferrer.getReferrerDetails()
.then((result) => console.log('HMSInstallReferrer getReferrerDetails, result:', result))
.catch((e) => console.warn('HMSInstallReferrer getReferrerDetails, error:', e));
HMSInstallReferrer.isReady()
Indicates whether the service connection is ready.
Return Type
| Type | Description |
| ------------------ | -------------------------------------------------- |
| Promise<boolean
> | Indicates whether the service connection is ready. |
Call Example
import {HMSInstallReferrer} from '@hmscore/react-native-hms-ads';
HMSInstallReferrer.isReady()
.then((result) => console.log('HMSInstallReferrer isReady, result:', result));
HMSInstallReferrer.allListenersRemove()
Remove all listeners for events of HMSInstallReferrer.
Call Example
import {HMSInstallReferrer} from '@hmscore/react-native-hms-ads';
HMSInstallReferrer.allListenersRemove();
Events
Events of HMSInterstitial
| Event | Description |
| -------------- | --------------------------------------------- |
| adFailed
| Event emitted when ad fails to load. |
| adClosed
| Event emitted when ad is closed. |
| adLeave
| Event emitted when the user leaves the app. |
| adOpened
| Event emitted when ad is displayed. |
| adLoaded
| Event emitted when ad loads. |
| adClicked
| Event emitted when ad is clicked. |
| adImpression
| Event emitted when ad impression is detected. |
Listener Functions of HMSInterstitial
| Functions | | ------------------------------------------------------------------------ | | adFailedListenerAdd | | adFailedListenerRemove | | adClosedListenerAdd | | adClosedListenerRemove | | adLeaveListenerAdd | | adLeaveListenerRemove | | adOpenedListenerAdd | | adOpenedListenerRemove | | adLoadedListenerAdd | | adLoadedListenerRemove | | adClickedListenerAdd | | adClickedListenerRemove | | adImpressionListenerAdd | | adImpressionListenerRemove |
HMSInterstitial.adFailedListenerAdd()
Adds listener for adFailed event. The listener function gets Error as input.
Parameters
| Name | Type | Description | | ---- | ---------------------------- | ------------------ | | fn | (res: Error )=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adFailedListenerAdd((error) => {
console.warn('HMSInterstitial adFailed, error: ', error);
});
HMSInterstitial.adFailedListenerRemove()
Removes listeners for adFailed event.
Call Example
HMSInterstitial.adFailedListenerRemove();
HMSInterstitial.adClosedListenerAdd()
Adds listener for adClosed event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adClosedListenerAdd(() => {
console.log('HMSInterstitial adClosed');
});
HMSInterstitial.adClosedListenerRemove()
Removes listeners for adClosed event.
Call Example
HMSInterstitial.adClosedListenerRemove();
HMSInterstitial.adLeaveListenerAdd()
Adds listener for adLeave event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adLeaveListenerAdd(() => {
console.warn('HMSInterstitial adLeave');
});
HMSInterstitial.adLeaveListenerRemove()
Removes listeners for adLeave event.
Call Example
HMSInterstitial.adLeaveListenerRemove();
HMSInterstitial.adOpenedListenerAdd()
Adds listener for adOpened event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adOpenedListenerAdd(() => {
console.log('HMSInterstitial adOpened');
});
HMSInterstitial.adOpenedListenerRemove()
Removes listeners for adOpened event.
Call Example
HMSInterstitial.adOpenedListenerRemove();
HMSInterstitial.adLoadedListenerAdd()
Adds listener for adLoaded event. The listener function gets InterstitialAd as input.
Parameters
| Name | Type | Description | | ---- | --------------------------------------------- | ------------------ | | fn | (res: InterstitialAd)=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adLoadedListenerAdd((interstitialAd) => {
console.log('HMSInterstitial adLoaded, Interstitial Ad: ', interstitialAd);
});
HMSInterstitial.adLoadedListenerRemove()
Removes listeners for adLoaded event.
Call Example
HMSInterstitial.adLoadedListenerRemove();
HMSInterstitial.adClickedListenerAdd()
Adds listener for adClicked event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adClickedListenerAdd(() => {
console.log('HMSInterstitial adClicked');
});
HMSInterstitial.adClickedListenerRemove()
Removes listeners for adClicked event.
Call Example
HMSInterstitial.adClickedListenerRemove();
HMSInterstitial.adImpressionListenerAdd()
Adds listener for adImpression event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSInterstitial} from '@hmscore/react-native-hms-ads';
HMSInterstitial.adImpressionListenerAdd(() => {
console.log('HMSInterstitial adImpression');
});
HMSInterstitial.adImpressionListenerRemove()
Removes listeners for adImpression event.
Call Example
HMSInterstitial.adImpressionListenerRemove();
Events of HMSSplash
| Event | Description |
| ---------------- | ------------------------------------ |
| adFailedToLoad
| Event emitted when ad fails to load. |
| adDismissed
| Event emitted when ad is dismissed. |
| adShowed
| Event emitted when ad is shown. |
| adLoaded
| Event emitted when ad loads. |
| adClick
| Event emitted when ad is clicked. |
Listener Functions of HMSSplash
| Functions | | ---------------------------------------------------------------------- | | adFailedToLoadListenerAdd | | adFailedToLoadListenerRemove | | adDismissedListenerAdd | | adDismissedListenerRemove | | adShowedListenerAdd | | adShowedListenerRemove | | adLoadedListenerAdd | | adLoadedListenerRemove | | adClickListenerAdd | | adClickListenerRemove |
HMSSplash.adFailedToLoadListenerAdd()
Adds listener for adFailedToLoad event. The listener function gets Error as input.
Parameters
| Name | Type | Description | | ---- | ---------------------------- | ------------------ | | fn | (res: Error )=> {} | Listener function. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.adFailedToLoadListenerAdd((error) => {
console.warn('HMSSplash adFailedToLoad, error: ', error);
});
HMSSplash.adFailedToLoadListenerRemove()
Removes listeners for adFailedToLoad event.
Call Example
HMSSplash.adFailedToLoadListenerRemove();
HMSSplash.adDismissedListenerAdd()
Adds listener for adDismissed event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.adDismissedListenerAdd(() => {
console.log('HMSSplash adDismissed');
});
HMSSplash.adDismissedListenerRemove()
Removes listeners for adDismissed event.
Call Example
HMSSplash.adDismissedListenerRemove();
HMSSplash.adShowedListenerAdd()
Adds listener for adShowed event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.adShowedListenerAdd(() => {
console.log('HMSSplash adShowed');
});
HMSSplash.adShowedListenerRemove()
Removes listeners for adShowed event.
Call Example
HMSSplash.adShowedListenerRemove();
HMSSplash.adLoadedListenerAdd()
Adds listener for adLoaded event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.adLoadedListenerAdd(() => {
console.log('HMSSplash adLoaded');
});
HMSSplash.adLoadedListenerRemove()
Removes listeners for adLoaded event.
Call Example
HMSSplash.adLoadedListenerRemove();
HMSSplash.adClickListenerAdd()
Adds listener for adClick event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSSplash} from '@hmscore/react-native-hms-ads';
HMSSplash.adClickListenerAdd(() => {
console.log('HMSSplash adClick');
});
HMSSplash.adClickListenerRemove()
Removes listeners for adClick event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
HMSSplash.adClickListenerRemove();
Events of HMSReward
| Event | Description |
| ---------------- | --------------------------------------------------- |
| adFailedToLoad
| Event emitted when ad fails to load. |
| adFailedToShow
| Event emitted when ad fails to be displayed. |
| adClosed
| Event emitted when ad is closed. |
| adOpened
| Event emitted when ad is opened. |
| adLoaded
| Event emitted when ad loads. |
| adRewarded
| Event emitted when a reward is provided. |
Listener Functions of HMSReward
| Functions | | ---------------------------------------------------------------------- | | adFailedToLoadListenerAdd | | adFailedToLoadListenerRemove | | adFailedToShowListenerAdd | | adFailedToShowListenerRemove | | adClosedListenerAdd | | adClosedListenerRemove | | adOpenedListenerAdd | | adOpenedListenerRemove | | adLoadedListenerAdd | | adLoadedListenerRemove | | adRewardedListenerAdd | | adRewardedListenerRemove |
HMSReward.adFailedToLoadListenerAdd()
Adds listener for adFailedToLoad event. The listener function gets Error as input.
Parameters
| Name | Type | Description | | ---- | ---------------------------- | ------------------ | | fn | (res: Error )=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adFailedToLoadListenerAdd((error) => {
console.warn('HMSReward adFailedToLoad, error: ', error);
});
HMSReward.adFailedToLoadListenerRemove()
Removes listeners for adFailedToLoad event.
Call Example
HMSReward.adFailedToLoadListenerRemove();
HMSReward.adFailedToShowListenerAdd()
Adds listener for adFailedToShow event. The listener function gets Error as input.
Parameters
| Name | Type | Description | | ---- | ---------------------------- | ------------------ | | fn | (res: Error )=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adFailedToShowListenerAdd((error) => {
console.warn('HMSReward adFailedToShow, error: ', error);
});
HMSReward.adFailedToShowListenerRemove()
Removes listeners for adFailedToShow event.
Call Example
HMSReward.adFailedToShowListenerRemove();
HMSReward.adClosedListenerAdd()
Adds listener for adClosed event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adClosedListenerAdd(() => {
console.log('HMSReward adClosed');
});
HMSReward.adClosedListenerRemove()
Removes listeners for adClosed event.
Call Example
HMSReward.adClosedListenerRemove();
HMSReward.adOpenedListenerAdd()
Adds listener for adOpened event.
Parameters
| Name | Type | Description | | ---- | ------- | ------------------ | | fn | ()=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adOpenedListenerAdd(() => {
console.log('HMSReward adOpened');
});
HMSReward.adOpenedListenerRemove()
Removes listeners for adOpened event.
Call Example
HMSReward.adOpenedListenerRemove();
HMSReward.adLoadedListenerAdd()
Adds listener for adLoaded event. The listener function gets RewardAd as input.
Adds listener for adClosed event.
Parameters
| Name | Type | Description | | ---- | --------------------------------- | ------------------ | | fn | (res: RewardAd)=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adLoadedListenerAdd((rewardAd) => {
console.log('HMSReward adLoaded, Reward ad: ', rewardAd);
});
HMSReward.adLoadedListenerRemove()
Removes listeners for adLoaded event.
Call Example
HMSReward.adLoadedListenerRemove();
HMSReward.adRewardedListenerAdd()
Adds listener for adRewarded event.
Parameters
| Name | Type | Description | | ---- | ----------------------------- | ------------------ | | fn | (res: Reward)=> {} | Listener function. |
Call Example
import {HMSReward} from '@hmscore/react-native-hms-ads';
HMSReward.adRewardedListenerAdd((reward) => {
console.log('HMSReward adRewarded, reward: ', reward);
});
HMSReward.adRewardedListenerRemove()
Removes listeners for adRewarded event.
Call Example
HMSReward.adRewardedListenerRemove();
Events of HMSInstallReferrer
| Event | Description |
| --------------------- | ---------------------------------------------------- |
| serviceConnected
| Event emitted when service connection is complete. |
| serviceDisconnected
| Event emitted when the service is crashed or killed. |
Listener Functions of HMSInstallReferrer
| Functions | | ----------------------------------------------------------------------------------------- | | serviceConnectedListenerAdd | | serviceConnectedListenerRemove | | serviceDisconnectedListenerAdd | | serviceDisconnectedListenerRemove |
HMSInstallReferrer.serviceConnectedListenerAdd()
Adds listener for serviceConnected event. The listener function gets InstallReferrerResponse as input.
Parameters
| Name | Type