### Install Project Dependencies Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-mlbody/example/README.md Installs all the necessary npm packages for the React Native project. This command should be run from the 'example' directory of the project. ```bash npm install ``` -------------------------------- ### Install Dependencies Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-adsprime/example/README.md Installs project dependencies using npm within the example folder. This command should be run before attempting to build or run the application. ```bash npm run i ``` -------------------------------- ### Install Dependencies and Run Android App Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-contactshield/example/README.md Commands to install project dependencies and then run the React Native application on an Android device or emulator. Assumes the project is set up within an 'example' folder. ```bash npm run i ``` ```bash react-native run-android ``` -------------------------------- ### Run the Android Demo App Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-push-fcm/example/README.md Starts the React Native demo application on an Android device or emulator. This command should be run from the project's root directory after installation. ```bash [project_path]> npm run android ``` -------------------------------- ### Install Dependencies and Run Android App Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-location/example/README.md These commands are used to manage the project dependencies and run the React Native application on an Android device. First, `npm run i` installs the necessary npm packages. Then, `react-native run-android` builds and deploys the application to a connected Android device or emulator. ```bash npm run i ``` ```bash react-native run-android ``` -------------------------------- ### Run Android Application Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-adsprime/example/README.md Builds and runs the React Native application on an Android device or emulator. This command is executed from the example folder. ```bash react-native run-android ``` -------------------------------- ### Install React-Native HMS Awareness Plugin Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-awareness/README.md This command installs the HMS Awareness plugin for React Native using npm. Ensure you have Node.js and npm installed on your system. This is the initial step to integrate the plugin into your project. ```bash npm i @hmscore/react-native-hms-awareness ``` -------------------------------- ### Install Huawei React-Native Push FCM Package Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-push-fcm/example/README.md Installs the necessary Huawei React-Native Push FCM package using npm. This command should be executed from the project's root directory. ```bash [project_path]> npm install @hmscore/react-native-hms-push-fcm ``` -------------------------------- ### Install React Native HMS Analytics Plugin Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-analytics/README.md This command installs the HUAWEI Analytics SDK for React Native applications using npm. It is a prerequisite for using the plugin's features. ```bash npm i @hmscore/react-native-hms-analytics ``` -------------------------------- ### HMS IAP: Setup Environment and Manage Sandbox Source: https://context7.com/hms-core/hms-react-native-plugin/llms.txt Set up the In-App Purchases (IAP) environment in your React Native application using HMS IAP Kit. This includes checking environment readiness, managing sandbox mode, enabling pending purchases, and controlling the logger. Ensure the HMS IAP module is installed. ```javascript import HMSIapModule from '@hmscore/react-native-hms-iap'; // Check if IAP environment is ready HMSIapModule.isEnvironmentReady(false) .then((res) => { console.log("Environment check:", res); if (res.returnCode === 0) { console.log("IAP environment is ready"); // Proceed with IAP operations } }) .catch((err) => console.error("Environment check failed:", err)); // Check if sandbox is activated HMSIapModule.isSandboxActivated() .then((res) => { console.log("Sandbox status:", res); }) .catch((err) => console.error("Sandbox check failed:", err)); // Enable pending purchase (for deferred payments) HMSIapModule.enablePendingPurchase() .then((res) => console.log("Pending purchase enabled:", res)) .catch((err) => console.error("Failed:", err)); // Enable/disable logger HMSIapModule.enableLogger() .then(() => console.log("Logger enabled")) .catch((err) => console.error("Failed:", err)); HMSIapModule.disableLogger() .then(() => console.log("Logger disabled")) .catch((err) => console.error("Failed:", err)); ``` -------------------------------- ### Install React-Native HMS Scan Plugin Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-scan/README.md Installs the Huawei Scan Kit plugin for React Native using npm. This is the initial step to integrate scanning functionalities into your React Native application. ```bash npm i @hmscore/react-native-hms-scan ``` -------------------------------- ### Map Kit: Basic Map Setup - JavaScript (React Native) Source: https://context7.com/hms-core/hms-react-native-plugin/llms.txt Sets up and displays a basic interactive Huawei map in a React Native application. Requires API key initialization and uses HMSMapView component with optional markers, polylines, and circles. Imports from '@hmscore/react-native-hms-map'. ```javascript import HMSMap from "@hmscore/react-native-hms-map"; import { HMSMapView } from "@hmscore/react-native-hms-map"; // Initialize map module with API key HMSMap.module.initializer("", "CN") .then(() => console.log("Map initialized")) .catch((err) => console.error("Initialization failed:", err)); // Basic map component console.log("Map ready")} onCameraIdle={(e) => console.log("Camera position:", e.nativeEvent)} > {/* Add markers */} console.log("Marker pressed")} /> {/* Add polyline */} {/* Add circle */} ``` -------------------------------- ### Configure Android Application ID in build.gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-analytics/example/README.md This code snippet shows how to set the unique Application ID for your Android app in the `build.gradle` file. Ensure this ID matches the Package Name in AppGallery Connect. It also mentions the need to update package names in manifest files and MainActivity.java. ```gradle defaultConfig { // Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). You may need to change the package name on AndroidManifest.xml and MainActivity.java respectively. // The Application ID here should match with the Package Name on the AppGalleryConnect applicationId "" } ``` -------------------------------- ### Scan Kit: Barcode and QR Code Scanning and Generation Source: https://context7.com/hms-core/hms-react-native-plugin/llms.txt This snippet covers barcode and QR code scanning using the device camera, including starting a default scan view, performing a custom scan with specific options, decoding barcodes from image bitmaps, and generating barcode images. ```javascript import ScanPlugin from "@hmscore/react-native-hms-scan"; // Start default scan view const startScan = () => { ScanPlugin.defaultScan({ scanType: ScanPlugin.ScanTypes.All // Scan all barcode types }) .then((result) => { console.log("Scan result:", { originalValue: result.originalValue, scanType: result.scanType, scanTypeForm: result.scanTypeForm }); }) .catch((err) => console.error("Scan failed:", err)); }; // Scan with custom view ScanPlugin.customizedScan({ scanType: ScanPlugin.ScanTypes.QRCode, // Only QR codes continuouslyScan: false, flashOnLightChange: true, isGalleryAvailable: true }) .then((result) => { console.log("QR Code:", result.originalValue); }) .catch((err) => console.error("Scan failed:", err)); // Decode image bitmap const barcodeImagePath = "data:image/png;base64,iVBORw0KGgoAAAANS..."; ScanPlugin.asynBarcodeDetector({ bitmapPath: barcodeImagePath, scanType: ScanPlugin.ScanTypes.All }) .then((results) => { results.forEach((result) => { console.log("Detected:", { type: result.scanType, value: result.originalValue }); }); }) .catch((err) => console.error("Decode failed:", err)); // Generate barcode ScanPlugin.buildBitmap({ content: "https://www.example.com", type: ScanPlugin.ScanTypes.QRCode, width: 300, height: 300, color: -16777216, // Black backgroundColor: -1 // White }) .then((bitmap) => { console.log("Generated barcode:", bitmap); // Use bitmap as image source }) .catch((err) => console.error("Generation failed:", err)); ``` -------------------------------- ### Install Huawei Health Plugin for React Native Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-health/README.md This command installs the Huawei Health Kit plugin for React Native using npm. Ensure you have Node Package Manager (npm) installed and configured in your project environment. ```bash npm i @hmscore/react-native-hms-health ``` -------------------------------- ### Configure Signing Certificate in build.gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-adsprime/example/README.md Specifies signing configuration details within the build.gradle file, including keystore file path, key alias, and passwords. This is crucial for verifying app authenticity when accessing HMS Core through the HMS SDK. ```gradle signingConfigs { config { storeFile file('') keyAlias '' keyPassword '' storePassword '' v1SigningEnabled true v2SigningEnabled true } } ``` -------------------------------- ### Configure Signing Certificate in Android Build Gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-location/example/README.md This code block demonstrates how to configure the signing certificate details within the `build.gradle` file for the Android application. It includes placeholders for the keystore file, key alias, key password, and store password. `v1SigningEnabled` and `v2SigningEnabled` should be set to `true` to enable both signing versions. ```gradle signingConfigs { config { storeFile file('') keyAlias '' keyPassword '' storePassword '' v1SigningEnabled true v2SigningEnabled true } } ``` -------------------------------- ### Android Signing Certificate Configuration for HMS Push Kit Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-push/example/README.md Configures the signing certificate details within the Android app's build.gradle file. This includes the keystore file, key alias, key password, and store password, which are essential for app authentication with Huawei services. ```gradle signingConfigs { config { storeFile file('') keyAlias '' keyPassword '' storePassword '' } } ``` -------------------------------- ### Configure Signing Certificate in Android Build Gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-push-fcm/example/README.md Specifies the keystore file, key alias, key password, and store password for signing the Android application. This is crucial for authenticating with HMS Core services. ```gradle signingConfigs { config { storeFile file('') keyAlias '' keyPassword '' storePassword '' } } ``` -------------------------------- ### Android App Configuration for HMS Push Kit Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-push/example/README.md Configures the Android application's build.gradle file to set the unique Application ID and prepares for package name changes in manifest files. This is a crucial step for AppGallery Connect integration. ```gradle defaultConfig { // Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). You may need to change the package name on AndroidManifest.xml and MainActivity.java respectively. // The Application ID here should match with the Package Name on the AppGalleryConnect applicationId "" // For ex: "com.example.mypushproject" } ``` -------------------------------- ### HMS Analytics: Configure Default Parameters and Restrictions Source: https://context7.com/hms-core/hms-react-native-plugin/llms.txt Configure advanced settings for HMS Analytics, including adding default parameters to all events, enabling/disabling ad ID collection, and managing user restrictions for GDPR compliance. This snippet requires the HMS Analytics SDK to be installed. ```javascript import HMSAnalytics from '@hmscore/react-native-hms-analytics'; // Add default event parameters (applied to all events) const defaultParams = { "app_version": "2.1.0", "user_type": "premium", "platform": "react-native" }; HMSAnalytics.addDefaultEventParams(defaultParams) .then(() => console.log("Default params added")) .catch((err) => console.error("Failed:", err)); // Enable/disable ad ID collection HMSAnalytics.setCollectAdsIdEnabled(false) .then(() => console.log("Ad ID collection disabled")) .catch((err) => console.error("Failed:", err)); // Set restriction (for GDPR compliance) HMSAnalytics.setRestrictionEnabled(false) .then(() => console.log("Restriction settings updated")) .catch((err) => console.error("Failed:", err)); // Check restriction status HMSAnalytics.isRestrictionEnabled() .then((res) => console.log("Restriction enabled:", res)) .catch((err) => console.error("Failed:", err)); // Delete user profile HMSAnalytics.deleteUserProfile("favor_sport") .then(() => console.log("Profile deleted")) .catch((err) => console.error("Failed:", err)); ``` -------------------------------- ### Configure Signing Certificate Fingerprint in Android Gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-ar/example/README.md This code configures the signing certificate details within the Android Gradle file. It includes placeholders for the keystore file, key alias, key password, and store password. These are essential for verifying app authenticity when accessing HMS Core services. ```gradle signingConfigs { config { storeFile file('') keyAlias '' keyPassword '' storePassword '' v1SigningEnabled true v2SigningEnabled true } } ``` -------------------------------- ### HMS Analytics: Track User Events and Behavior Source: https://context7.com/hms-core/hms-react-native-plugin/llms.txt Implement event tracking for user behavior and custom events using HMS Analytics Kit. This includes initializing the SDK, enabling/disabling collection, setting user identifiers and profiles, and tracking both custom and predefined events. Ensure the HMS Analytics SDK is correctly installed. ```javascript import HMSAnalytics from '@hmscore/react-native-hms-analytics'; // Initialize analytics instance (Android only) HMSAnalytics.getInstance() .then((res) => console.log("Analytics initialized")) .catch((err) => console.error("Initialization failed:", err)); // Enable/disable analytics collection HMSAnalytics.setAnalyticsEnabled(true) .then(() => console.log("Analytics enabled")) .catch((err) => console.error("Failed to enable:", err)); // Set user ID HMSAnalytics.setUserId("user12345") .then(() => console.log("User ID set")) .catch((err) => console.error("Failed to set user ID:", err)); // Set user profile attributes HMSAnalytics.setUserProfile("favor_sport", "volleyball") .then(() => console.log("User profile set")) .catch((err) => console.error("Failed to set profile:", err)); // Track custom event const eventId = "add_to_cart"; const bundle = { "product_id": "SKU123", "product_name": "Blue Sneakers", "quantity": 2, "price": 49.99 }; HMSAnalytics.onEvent(eventId, bundle) .then(() => console.log("Event tracked")) .catch((err) => console.error("Event tracking failed:", err)); // Track predefined event HMSAnalytics.onEvent( HMSAnalytics.HAEventType.ADDPRODUCT2WISHLIST, { [HMSAnalytics.HAParamType.PRODUCTID]: "SKU456", [HMSAnalytics.HAParamType.PRODUCTNAME]: "Red Hat" } ) .then(() => console.log("Wishlist event tracked")) .catch((err) => console.error("Failed:", err)); // Set session duration (milliseconds) HMSAnalytics.setSessionDuration(1500000) .then(() => console.log("Session duration set")) .catch((err) => console.error("Failed:", err)); ``` -------------------------------- ### Configure Application ID in build.gradle Source: https://github.com/hms-core/hms-react-native-plugin/blob/master/react-native-hms-adsprime/example/README.md Sets the unique Application ID in the app-level build.gradle file. This ID must match the Package Name defined in AppGallery Connect for proper communication with Huawei services. Ensure package names in manifest files are also updated. ```gradle defaultConfig { // The Application ID here should match with the Package Name on the AppGalleryConnect applicationId "" // Other configurations ... } ```