Integrate SDK components

By integrating Android IAPMiniProgram SDK, the basic capabilities of mini-programs are included in your project. However, due to package size concerns, enhanced capabilities of Android IAPMiniProgram SDK are not included by default.

You can enhance the SDK capabilities by integrating the following pre-defined SDK components:

  • Map: This component allows users to implement one of the following types of map capabilities in your mini programs:

Note: Google Maps and HUAWEI Maps cannot coexist. You can only choose one for integration based on your business demands.

Notes:

  • If a component is not integrated, mini programs will encounter errors when calling JSAPIs related to the component.
  • For third-party super apps, if you do not integrate certain components, it is recommended to remove the related JSAPI documentation from your documentation center to avoid unexpected errors.

Integrate the Google Map component

To allow users to call Google Maps in your mini-programs, you need to integrate the Map component into your project by taking the following steps:

Step 1: Integrate Google Maps SDK

You need firstly integrate Google Maps SDK by taking the following steps:

  1. Get a Google API key. For step-by-step instructions, see Using API Keys in Google's documentation.
  2. Save the API key to the local.properties file as below.
copy
MAPS_API_KEY=YOUR_API_KEY
  1. Update the build.gradle file to inject the mapsApiKey variable into the AndroidManifest.xml file as below.

build.gradle file:

copy
android {
    defaultConfig {
        // ...
        // Set the properties within 'local.properties' into a 'Properties' class so that values
        // within `local.properties` (e.g. Maps API key) are accessible in this file.
        Properties properties = new Properties()
        if (rootProject.file("local.properties").exists()) {
           properties.load(rootProject.file("local.properties").newDataInputStream())
        }
        manifestPlaceholders = [ mapsApiKey : properties.getProperty("MAPS_API_KEY", "") ]
    }
}

AndroidManifest.xml file:

copy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <application
    android:name="com.alipay.iapminiprogram.DemoApplication"
    android:allowBackup="false"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    ...
    <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="${mapsApiKey}" />
  </application>

</manifest>

Step 2: Add the Maven repository

Add the Maven repository in your root build.gradle file with the following code:

copy
repositories{
    jcenter()
}

Step 3: Add the Multimap dependencies

Add the Multimap dependencies in the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-gmultimap:${iapminiprogram_version}"
}

(Optional) Step 4: Prevent specific mini-programs from using your app's API key

If a mini-program does not provide a Google API key, your app's API key is used by default. To avoid charging your app unreasonable fees on Google Maps services used in specific mini-programs, you need to prevent the mini-programs from using your app's API key. Take the following steps:

  1. Implement GriverMapCustomAPIKeyExtension with either of the following codes:

Kotlin

copy
class DemoGriverMapCustomAPIKeyExtension: GriverMapCustomAPIKeyExtension {
    override fun canUseGoogleAPIKey(appId: String?): Boolean {
        return false
    }
}

Java

copy
public class DemoGriverMapCustomAPIKeyExtension implements GriverMapCustomAPIKeyExtension {
    @Override
    public boolean canUseGoogleAPIKey(String appId) {
        return false;
    }
}
  1. Register the Extension after the SDK is initialized as below.
copy
Griver.registerExtension(new GriverExtensionManifest(GriverMapCustomAPIKeyExtension.class, new DemoGriverMapCustomAPIKeyExtension()));

More information

For more information about the Map components, see the following documents:

Integrate the HUAWEI Maps component

To allow users to call HUAWEI Maps in your mini-programs, you need to integrate the Map component into your project by taking the following steps:

Step 1: Integrate HUAWEI Maps SDK

You need firstly integrate HUAWEI Maps SDK by taking the following steps:

  1. Get a HUAWEI API key. For step-by-step instructions, see Obtaining the API Key in HUAWEI documentation.
  2. Save the API key to the local.properties file as below.
copy
HW_MAPS_API_KEY=YOUR_API_KEY
  1. Update the build.gradle file to add the hwMapsApiKey variable into the AndroidManifest.xml file as below.

build.gradle file:

copy
android {
    defaultConfig {
        // ...
        // Set the properties within 'local.properties' into a 'Properties' class so that values
        // within `local.properties` (e.g. Maps API key) are accessible in this file.
        Properties properties = new Properties()
        if (rootProject.file("local.properties").exists()) {
           properties.load(rootProject.file("local.properties").newDataInputStream())
        }
        manifestPlaceholders = [ hwMapsApiKey : properties.getProperty("HW_MAPS_API_KEY", "") ]
    }
}

AndroidManifest.xml file:

copy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <application
    android:name="com.alipay.iapminiprogram.DemoApplication"
    android:allowBackup="false"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    ...
    <meta-data
      android:name="com.huawei.android.geo.API_KEY"
      android:value="${hwMapsApiKey}" />
  </application>

</manifest>

Step 3: Add the Maven repository

Add the Maven repository in your app-level root build.gradle file with the following code。

Note: There are different ways to add the Maven repository based on the different Gradle plugin version. For details, see Configuring the Maven Repository Address for the HMS Core SDK in HUAWEI documentation.

copy
repositories{
    maven { url 'https://developer.huawei.com/repo/' }
}

Step 4: Add the AGC plugin dependencies

Per your demands, add the AGC (AppGallery Connect) plugin dependencies in the app-level build.gradle file with the following code. For more information, see Adding Build Dependencies in HUAWEI documentation.

  • 1st way: Add the following configuration under the declaration in the file header.
copy
apply plugin: 'com.huawei.agconnect'
  • 2nd way: Add the plugin configuration in the plugins block.
copy
plugins {
    id 'com.android.application'
    // Add the following configuration
    id 'com.huawei.agconnect'
}

Step 5: Add the Multimap dependencies

Add the Multimap dependencies in the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-hwmultimap:${iapminiprogram_version}"
}

(Optional) Step 6: Prevent specific mini-programs from using your app's API key

If a mini-program does not provide a HUAWEI API key, your app's API key is used by default. To avoid charging your app unreasonable fees on HUAWEI Maps services used in specific mini-programs, you need to prevent the mini-programs from using your app's API key. Take the following steps:

  1. Implement GriverMapCustomAPIKeyExtension with either of the following codes:

Kotlin

copy
class DemoGriverMapCustomAPIKeyExtension: GriverMapCustomAPIKeyExtension {
    override fun canUseHuaweiAPIKey(appId: String?): Boolean {
        return false
    }
}

Java

copy
public class DemoGriverMapCustomAPIKeyExtension implements GriverMapCustomAPIKeyExtension {
    @Override
    public boolean canUseHuaweiAPIKey(String appId) {
        return false;
    }
}
  1. Register the Extension after the SDK is initialized as below.
copy
Griver.registerExtension(new GriverExtensionManifest(GriverMapCustomAPIKeyExtension.class, new DemoGriverMapCustomAPIKeyExtension()));

More information

For more information about the Map components, see the following documents:

Integrate the Video component

To allow users to play videos in your mini-programs, you need to integrate the Video component into your project.

Add the Video dependencies in the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-video:${iapminiprogram_version}"
}

For more information about the Video component, see my.createVideoContext.

Integrate the Lottie component

To allow users to implement the Lottie capabilities in your mini-programs, you need to integrate the Lottie component into your project.

Add the Lottie dependencies in the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-lottie:${iapminiprogram_version}"
}

For more information about the Lottie component, see my.createLottieContext.

Integrate the Livestreaming component

To allow users to play live-streaming videos in your mini-programs, you need to integrate the Livestreaming component into your project.

Add the Livestreaming dependencies in the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-media:${iapminiprogram_version}"
}

For more information about the Livestreaming component, see my.createLivePlayerContext.

Integrate the Bluetooth component

To allow users to implement the Bluetooth capabilities in your mini-programs, you need to integrate the Bluetooth component into your project.

Add the Bluetooth dependencies to the app-level build.gradle file with the following code:

copy
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram-bluetooth:${iapminiprogram_version}"
}

For more information about the Bluetooth component, see Bluetooth JSAPIs.

Integrate the Biometric Authentication component

To enable users to implement biometric authentication capabilities in your mini programs, you must integrate the Biometric Authentication component into your project.

Before integrating, ensure that your Android IAPMiniProgram SDK version is 2.51.0 or later. Then add the Biometric Authentication dependencies to the app-level build.gradle file with the following code:

copy
dependencies {
  implementation "com.alipay.plus.android:iapminiprogram-bioauth:${iapminiprogram_version}"
}

During your app packaging process, the SDK can automatically include the following <uses-permission> elements in the app's manifest file:

copy
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

For more information about the Biometric Authentication component, see Biometric authentication API overview.