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: With this component integrated into your app, users can implement the Google Map capabilities in your mini-programs. For more information, see Integrate the Map component.
- Video: With this component integrated into your app, users can play videos in your mini-programs. For more information, see Integrate the Video component.
- Lottie: With this component integrated into your app, users can implement the Lottie capabilities in your mini-programs. For more information, see Integrate the Lottie component.
- Livestreaming: With this component integrated into your app, users can play live-streaming videos in your mini-programs. For more information, see Integrate the Livestreaming component.
- Bluetooth: With this component integrated into your app, users can implement the Bluetooth capabilities in your mini-programs. For more information, see Integrate the Bluetooth component.
Note: If a component is not integrated, the mini-program encounters the error code
1
(JSAPI not existed
) when calling JSAPIs related to the component.
Integrate the 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:
- Get a Google API key. For step-by-step instructions, see Using API Keys in Google's documentation.
- Save the API key to the local.properties file as below.
MAPS_API_KEY=YOUR_API_KEY
- Update the build.gradle file to inject the mapsApiKey variable into the AndroidManifest.xml file as below.
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", "") ]
}
}
Step 2: Add the Maven repository
Add the Maven repository in your root build.gradle file with the following code:
repositories{
jcenter()
}
Step 3: Add the Maps dependencies
Add the Maps dependencies in the app-level build.gradle file with the following code:
dependencies {
implementation "com.alipay.plus.android:iapminiprogram-gmap:${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:
- Implement
GriverMapCustomAPIKeyExtension
with either of the following codes:
Kotlin
class DemoGriverMapCustomAPIKeyExtension: GriverMapCustomAPIKeyExtension {
override fun canUseGoogleAPIKey(appId: String?): Boolean {
return false
}
}
Java
public class DemoGriverMapCustomAPIKeyExtension implements GriverMapCustomAPIKeyExtension {
@Override
public boolean canUseGoogleAPIKey(String appId) {
return false;
}
}
- Register the
Extension
after the SDK is initialized as below.
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:
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:
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:
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 in the app-level build.gradle file with the following code:
dependencies {
implementation "com.alipay.plus.android:iapminiprogram-bluetooth:${iapminiprogram_version}"
}
For more information about the Bluetooth component, see Bluetooth JSAPIs.