Using the BBWebView library
The BlackBerry Dynamics SDK contains the BBWebView library that you can use to integrate the Android WebView component with a BlackBerry Dynamics app. The BBWebView code is available under the com.blackberry.bbwebview package name.
The BBWebView library supports secure HTTP request interception for an internal network (URL loading, XML, and fetch HTTP requests), data leakage protection for cut, copy, and paste, page history navigation, and a secure cookies store. Additionally, HTTP authentication (Basic, Digest, NTLM, Kerberos) is supported in the BBWebView library.
The BBWebview library also supports file downloading into the secure container and showing the downloaded text (txt), image (jpeg, jpg, png), audio (mp3), and video (mp4) files to the user. You can get the path to the BBWebView Download directory and access downloaded files using the BlackBerry Dynamics Secure Storage APIs (com.good.gd.file). You can also open the BBWebView library UI to show the content of the BBWebView directory to the user.
- com.blackberry.bbwebview.BBWebChromeClient
- com.blackberry.bbwebview.BBWebViewClient
- com.blackberry.bbwebview.BBWebView
- Loading HTTP and HTTPS data
- Redirection
- Basic, Digest, NTLM, and Kerberos
- Cookies
- Video and audio playback
- Asynchronous XHR requests
- WebSockets are supported with the following limitations:
- ServerTrust challenge
- bufferedAmount property for WebSocket JavaScript object
- Basic, Digest, NTLM, and Kerberos authentication
- URL schemes (mailto:, geo:, and so on)
- Web worker (Service worker)
- Pasting content from a BlackBerry Dynamics app to WebView using drag and drop
- Resource caches
- Secure database
- Local storage (HTML5)
- Session storage
- AutoZSO
- Secure drag-and-drop data movement between applications
- Dynamically created HTML iframes
To load files from the local assets folder, you must use the web-like URL format https://appassets.androidplatform.net/assets/ rather than file:///android_asset/. For example, the following code will load the index.html page from the assets folder in BBWebView:
// Initialize BBWebView instance
BBWebView webView = ...
// Provide url with file name which is located in your application's assets folder
webView.loadUrl("https://appassets.androidplatform.net/assets/index.html");
This method is compatible with the Same-Origin policy and recommended by Google. For more information, see WebViewAssetLoader.
- For WebViewClient, use the setter detailed at Android Developers WebView.
- For WebChromeClient, use the setter detailed at Android Developers WebView.
webView = ... // Create BBWebView instance
webView.setWebViewClient(new BBWebViewClient() {
@Override
public boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) {
if (request.getUrl().toString().startsWith("https://example.com")) {
Log.i("BBWebViewClient", "shouldOverrideUrlLoading() forbidden loading url");
return true;
} else {
Log.i("BBWebViewClient", "shouldOverrideUrlLoading() continue loading url");
return false;
}
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("BBWebViewClient", "onPageFinished() url is loaded");
}
});
webView.setWebChromeClient(new BBWebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
Log.i("BBWebChromeClient", "onProgressChanged() progress = " + newProgress);
}
});