1 / 20

Cosc 4755

Cosc 4755. Blackberry and Android Embedding the browser in your app. Embedding the browser. For many applications, you may not nothing more then the web browser But you want your “Company Name” on it The company web server can now serve all the contain needed.

jackie
Download Presentation

Cosc 4755

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cosc 4755 Blackberry and Android Embedding the browser in your app

  2. Embedding the browser • For many applications, you may not nothing more then the web browser • But you want your “Company Name” on it • The company web server can now serve all the contain needed. • Almost never have to update the app with new stuff. • But the company web server, must serve the data that is in the “size of the screen”.

  3. Browser object • Android webkit • android.webkit • WebView, a simple but very powerful widget • Blackberry • net.rim.device.api.browser.field 4.0.0+ • powerful, but complex. • Requires code signing to use outside the simulator • net.rim.device.api.browser.field2 V5.0.0+ • BrowserField, simple but very powerful field • does NOT require code signing.

  4. Android

  5. Android webkit • In the simplest form • Put a WebView Widget in the layout • If you want javascript enabled mWebView. getSettings().setJavaScriptEnabled(true); • Now load a page mWebView.loadUrl("http://www.cs.uwyo.edu"); • In androidManifest.xml, you need to request permission to use the internet. • Add this • <uses-permission android:name="android.permission.INTERNET" />

  6. Android webkit (2) • How to handle everything else. • In the previous slide, if a use clicks on a link, the android browser will now open and you app is paused. • To better control the browser you extend the WebViewClient class • Then add that to the WebView mWebView.setWebViewClient(new myWebViewClient());

  7. WebViewClient • This controls the functions and gives you app’s notifications about what is going on. • booleanshouldOverrideUrlLoading(WebViewview, String url) • Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. • return true, if handled, otherwise false. • onReceivedError(WebView view, interrorCode, String description, String failingUrl) • Report an error to the host application. • Other that maybe useful • onPageStarted, onPageFinished, onReceivedSslError, shouldOverrideKeyEvent, onUnhandledKeyEvent

  8. WebViewClient Example private class CallBack extends WebViewClient { public booleanshouldOverrideUrlLoading(WebView view, String url) { browser.loadUrl(url); return true; } } • I’ve only overriding one method, since I wanted to prevent the web browser from launching.

  9. WebView methods • reload(), which refreshes the page • goBack(), which goes back one step in the browser history • canGoBack() returns true if there is at least one step back in the history • goForward(), which goes forward one step in the browser history • canGoForward(), returns true if you can. • ZoomIn(), ZoomOut(), stopLoading(), clearcache() and clearHistory() just to name a few.

  10. WebViewClient example 2 //continuing the example, we add a keylistener to handle the back button @Override public booleanonKeyDown(intkeyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } • We can also create buttons, for refresh, forward, and back. • Even a progress bar using the getProgress() method in WebView.

  11. The Rest • Cache • CacheManager and CacheManger.CacheResult gives you access in the browser cache system • Cookies • CookieManager and CookieSyncManger gives you access to the cookies • WebSettings • Gives you access to dozens of settings, including • To enable the built-in zoom, set WebSettings.setBuiltInZoomControls(boolean) • Change the UserAgentString • This is also where the javascript settings are as well. • Can use mWebView.getSettings() which returns a WebSettings object which can be used to control the settings.

  12. Blackberry

  13. BrowserField • We are going to skip over browser.field and use the browser.field2 package. • To use the basics • Declare the BrowserField and add it to the screen. • BrowserField.requestContent(URL); • The content of the webpage will be displayed on the screen, using the whole screen • Assuming it is the only field added.

  14. Configuring. • By default most things are turned on with the browserfield. • Use BrowserFieldConfig object to configure BrowserFieldConfigconfig = new BrowserFieldConfig(); config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE); //default is false config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE); //default is already true. config.setProperty(BrowserFieldConfig.ENABLE_COOKIES, Boolean.TRUE); //default is already true. browser = new BrowserField(config);

  15. BrowserField (2) • You can use the following to control what is displayed in the field • go forward or back on page • forward(), back() • fresh() • setZoomScale(float scale) and float getZoomScale() to control how the page is zoomed. • A note, when browserfield has focus, the BB menu will allow the user to zoom fully out, when it has been “zoomed in”.

  16. BrowserField(3) • BrowserFieldHistorygetHistory() • which returns the browser history of current field • Document getDocuement() • returns a Document object (xml), which is likely a subinterfaceHTMLDocument object. • getDocumentTitle() and getDocumentUrl() • returns a String with the info • BrowserFieldListener • A listener how the page is “working”

  17. BrowserFieldHistory • Methods in the BrowserFieldHistory object • booleancanGoBack() • This method returns true iff there are pages backwards in the history • goBack() • This method will find the previous page loaded into this BrowserField instance and reload it • booleancanGoForward() • This method returns true iff there are pages forwards in the history • goForward() • This method will find the next page in this BrowserField instance's history and reload it • go(intdistance) • This method will find the page a certain distance forward or backwards from the current page and load that pages • clearHistory() and refresh()

  18. BrowserFieldHistory Example • Check the history to see if we can go back one page BrowserFieldHistorybrowserFieldHistory = browser.getHistory(); if(browserFieldHistory.canGoBack()) { //causes the bowserfield to back one. browserFieldHistory.goBack(); } • OR browser.back() //goes back one page if it can.

  19. BrowserFieldListener • These are the methods can be overriding by extending BrowserFieldLisetner • documentAborted(BrowserFieldbrowserField, Document document) • documentCreated(BrowserFieldbrowserField, ScriptEnginescriptEngine, Document document) • documentError(BrowserFieldbrowserField, Document document) • documentLoaded(BrowserFieldbrowserField, Document document) • documentUnloading(BrowserFieldbrowserField, Document document) • downloadProgress(BrowserFieldbrowserField, ContentReadEvent event) • Except there is no documentation about when/why they are called. • DocumentLoaded is called when the BrowserField has finished loading • DocumentError seems to be called when the document fails to load

  20. Q A &

More Related