Listen for the URL navigation event
When IAPMiniProgram SDK loads a URL, it uses WebView to load the page. If you want to open some URLs in your browser, you can intercept the URL navigation process of SDK by implementing the GriverUrlNavigationEvent interface. Each time when SDK loads a URL, it sends out the GriverUrlNavigationEvent interface and you can intercept it.
Procedures
To intercept for the mini program load url events, complete the following steps:
Step 1: Implement the GriverUrlNavigationEvent interface
Implement the GriverUrlNavigationEvent interface and write your business logic in the onStartUrlNavigationand allowLoadUrl method. Refer to the following sample on how to implement the interface.
class DemoGriverUrlNavigationEventHandler : GriverUrlNavigationEvent {
override fun onStartUrlNavigation(page: Page?, url: String?): Boolean {
return false
}
override fun allowLoadUrl(page: Page?, url: String?): Boolean {
return false
}
override fun onInitialized() {
}
override fun onFinalized() {
}
}
Step 2: Register the DemoGriverUrlNavigationEventHandler class
Call the registerEventHandler interface to register the URL navigation event after initializing the SDK. For details, see the following GriverUrlNavigationEvent interface.
Code sample:
Griver.registerEventHandler(
GriverEventManifest(
DemoGriverUrlNavigationEventHandler::class.java.name,
Arrays.asList(GriverUrlNavigationEvent::class.java.name), Page::class.java
)
)Structures
GriverUrlNavigationEvent interface
The definition of the GriverUrlNavigationEvent interface is shown in the following code:
interface GriverUrlNavigationEvent : GriverEvent {
fun onStartUrlNavigation(page: Page?, url: String?): Boolean
fun allowLoadUrl(page: Page?, url: String?): Boolean
}Based on the definition, this interface provides the following methods:
Method Name | Description |
This method is called when SDK opens a new page through the URL.
| |
onStartUrlNavigation | This method will be called when SDK opens a new page through url.
|
allowLoadUrl method
Parameter | Data type | Required | Description |
page | Page | Yes | Loads the current page object of the URL. |
url | String | Yes | The URL address to be loaded. |