Extending WebViewClient, I overrode the method shouldOverrideUrlLoading as follows:
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { String mainPage = "https://www.secureSite.com/myData/"; if (url.startsWith(mainPage)) { view.loadUrl(url); return false; } else { //some dialog building code here view.stopLoading(); return false; } } // end-of-method shouldOverrideUrlLoading
So the point of this code is that it evaluates each URL that your app starts loading. If a user finds a link or tries to load their own URL that is NOT part of your domain/specified URL, then it won't match and won't load.
But in your android manifest, you should set the android:exported attribute to false to prevent other applications from using it.
Quote below from here:
android:exported Whether or not components of other applications can invoke the service or interact with it — "true" if they can, and "false" if not. When the value is "false", only components of the same application or applications with the same user ID can start the service or bind to it.
The default value depends on whether the service contains intent filters. The absence of any filters means that it can be invoked only by specifying its exact class name. This implies that the service is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the service is intended for external use, so the default value is "true".
This attribute is not the only way to limit the exposure of a service to other applications. You can also use a permission to limit the external entities that can interact with the service (see the permission attribute).
This attribute can be used in an Activity and Provider, also. Here (activity) and here (provider) is the reference, but it is pretty much word for word the same as the Service description, just substitute Activity or Provider for Service.