uMobile PhoneGap Custom URL Handling
URL Handling Use Cases
1. Session management
The existing Titanium app updates an internal session timer each time a portal URL is accessed. Â If the session timer indicates that the app likely hasn't been used in a longer period of time than the configured session timeout, the app checks for a session via an AJAX request. Â If no session exists, the app runs back through the authentication / session establishment logic before requesting the portlet URL. Â This prevents the app from breaking if the user leaves the device idle for some period of time without restarting the app.
2. Inter-module links
The existing app also watches for special URLs that link to the map or directory modules. Â Since we have native versions of those modules, the app displays those native modules rather than following the WebView link as usual.
As an example, the courses portlet might link to an instructor's contact information via the URL "/s/person?id=username" or to the meeting location for a course via "/s/location?id=buildingcode". Â On the browser side, these URLs are mapped to portlets and redirected to the appropriate portlet URL. Â The native app needs to watch for these URLs, catching them before the redirect, and replacing the WebView with a native component.
3. External websites
We currently allow adopters to configure external (non-portal) sites to be displayed as uMobile modules. Â For example, take a look at the transit or library modules in the default uMobile install. Â When those external sites are displayed, the current app adds a back button in case the external site doesn't have its own navigation controls.Â
Implementation
On Android, it appears that we can implement custom URL handling by extending CordovaWebViewClient. Â We specifically override the onLoadResource method to check each URL against a list of regexes. Â When we need to handle one specially, we can call ctx.loadUrl with some alternate local file URL, bypassing the normal WebView behavior. Â The most practical URL to load is likely simply the main index.html file, perhaps passing in parameters to indicate that the session must be reloaded, or that the view should be initialized to a particular local module.
We need to explore implementation options on other platforms.
Â
Â