GriverMapCustomAPIKeyExtension
In the IAPMiniProgram SDK, if a mini program does not provide a Google API key or a Huawei API key, your app API key is used by default. To avoid charging your app unreasonable fees on Google or Huawei Maps service that is used in specific mini programs, you need to prevent the mini programs from using your app API key. Follow this topic to avoid using your app API key.
Procedures
To prevent the mini programs from using your app API key, follow these steps:
Step 1. Implement the GriverMapCustomAPIKeyExtension interface
Implement the GriverMapCustomAPIKeyExtension interface and write code in the required methods according to your business logic.
Code sample as follows:
class CustomMapCustomAPIKeyExtensionImpl : GriverMapCustomAPIKeyExtension{
override fun canUseGoogleAPIKey(appId: String?): Boolean {
return false
}
override fun canUseHuaweiAPIKey(appId: String?): Boolean {
return false;
}
}
Step 2: Register the CustomMapCustomAPIKeyExtensionImpl class
Refer to the following sample code and call the registerExtension interface to register the CustomMapCustomAPIKeyExtensionImpl class after initializing the SDK.
IAPConnect.init(application, initConfig, object : InitCallback() {
fun onSuccess() {
//ยทยทยท
Griver.registerExtension(
GriverExtensionManifest(
GriverMapCustomAPIKeyExtension::class.java,
CustomMapCustomAPIKeyExtensionImpl()
)
)
}
})
Interface
GriverMapCustomAPIKeyExtension interface
The definition of the GriverMapCustomAPIKeyExtension interface is shown in the following codes:
interface GriverMapCustomAPIKeyExtension : GriverExtension {
fun canUseGoogleAPIKey(appId: String?): Boolean
fun canUseHuaweiAPIKey(appId: String?): Boolean
}
Methods
Based on the definition above, this interface provides the following methods:
Method | Description |
Returns the result of whether the current If:
| |
Returns the result of whether the current If:
|
canUseGoogleAPIKey method
Parameter | Data type | Required | Description |
appId | String | No | The mini program |
canUseHuaweiAPIKey method
Parameter | Data type | Required | Description |
appId | String | No | The mini program |