Blackberry BrowserField Base Url

865 views Asked by At

I have been trying to show some HTML content from SD card in the browser Field and every time instead of rendering the HTML data,browser Field renders the Base URL.I tried to find the reason for the same and couldn't get any solution.I didn't find any documentation that clearly explains when that base URL is called.Can any one please explain why and when is that Base URL called? Any Help is highly appreciated...

Thanks in advance.

2

There are 2 answers

0
Govindarao Kondala On

May be it will help you. This answer explain how to display html content from sdcard in two ways

1)Read data as text file and add it to String and dislay that content like following way

StringBuffer sb1;                 

                FileConnection fconn = (FileConnection)Connector.open("filepath="file:///SDCard/BlackBerry/documents/HtmlFileName.txt", Connector.READ_WRITE);
                if (fconn.exists())
                {
                    InputStream input=fconn.openDataInputStream();
                    sb1=new StringBuffer();
                    int chars,i=0;
                    while((chars=input.read())!=-1)
                    {
                        sb1.append((char)chars);
                    }

               }

    String str=sb1.toString();

    VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLL_MASK);
    BrowserFieldConfig browserFieldConfig = new BrowserFieldConfig();
    browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
    browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_CARET);
    browserFieldConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);
    browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE_POINTER.toString(),Boolean.TRUE);
    browserFieldConfig.setProperty(BrowserFieldConfig.ALLOW_CS_XHR,Boolean.TRUE);
    BrowserField browser_field=new BrowserField(browserFieldConfig);
    browser_field.displayContent(str,"");
        vfm.add(browser_field);
        add(vfm);

2)You can directly call that page from browserfield like following

String url="file:///sdcard/index.html";//specify exact path if resource then local:///.if sd card file:///
    VerticalFieldManager manager=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR){
                protected void sublayout(int maxWidth, int maxHeight) {
                    super.sublayout(640,Display.getHeight());
                    setExtent(640,Display.getHeight());
                }
            };
            BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
                myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
                BrowserField browserField = new BrowserField(myBrowserFieldConfig);
                history=browserField.getHistory();
                browserField.requestContent(url);
                manager.add(browserField);
                browserField.requestContent(url);
                add(manager);
0
Steven Collins On

I realize this is a little old, but I had the same problem and wanted to share how I solved my case.

It turns out that if you try to navigate to a new page in the BrowserField and the new page can't be loaded or an error occurs, the BrowserField will load the Base URL.

This issue occurred twice to me. In one instance, my program threw a runtime exception which was handled silently (by accident). This caused the navigation to fail and the Base URL to load. In the second instance, the page I was attempting to navigate to did not exist (either by misspelling or misuse of file names or locations).

Just to be clear, it was the Base URL of the original page which was loaded, not the page that failed to load.

I hope this helps!