Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified
Accepted Solution

Loading a local html file in the browser

[ Edited ]

I'm writing an embedded browser app right now and I was wondering if I can get the browser to load a html file stored locally? This way I can minimize the start-up load time of the embedded browser.

 

So far the directory of all my files are as following and I'm trying to load up test.html:

 

Sourcecode <folder>

Web

test.html

main.java

 

FYI, I am using the WebIcon sample code as a base.
Message Edited by jcr on 04-09-2009 11:19 AM
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Loading a local html file in the browser

Check this KB Article.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800440/How_To_...

Use Search. "Accept Solution" If the problem is resolved.
Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified

Re: Loading a local html file in the browser

But that code goes to http://www.blackberry.com:80 not a local html file.

Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified

Re: Loading a local html file in the browser

any other help?
Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Loading a local html file in the browser

if you take a closer look at the example given you can see that the html file is first downloaded (indeed from blackberry.com:80) and then handled.
you can replace the downloading with reading the file from your project, the sd card or wherever you have it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified

Re: Loading a local html file in the browser

Well when I'm working in JDE, I am importing the folder and html file into my workspace. How do I call that file up?
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Loading a local html file in the browser

Hi,

 

May be this link will help you out

 

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=28606#M28606

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified

Re: Loading a local html file in the browser

To invoke the sample code

 

public Field getPage() { String filename = "foo.html"; InputStream is = getClass().getResourceAsStream(filename); RenderingSession r = RenderingSession.getNewInstance(); browserContent = r.getBrowserContent(null, is, null, 0); Field field = browserContent.getDisplayableContent(); return(field); }

 

In the Main method, I just have to put:

Field sample = getPage();

 

Or am I missing something? Sorry for my noob questions, having touch this Java stuff in a while. What else do I need to import?

Developer
Developer
Posts: 42
Registered: ‎04-01-2009
My Device: Not Specified

Re: Loading a local html file in the browser

Actually more like I'm getting error on this line:

 

browserContent = r.getBrowserContent(null, is, null, 0);

Here is the code, what is wrong with it?

import java.io.*;
import javax.microedition.io.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.Field;
import net.rim.device.api.browser.field.BrowserContent;
import net.rim.device.api.browser.field.RenderingSession;



/**
 * 
 */
class localHTML {
    localHTML() {    }
    
    public static void main(String[] args)
        {
            getPage();
            
        }
        
    public Field getPage()
    {
        BrowserContent browserContent;
        String filename = "Foo.html";
        InputStream is = getClass().getResourceAsStream(filename);
        RenderingSession r = RenderingSession.getNewInstance();
        browserContent = r.getBrowserContent(null, is, null, 0);
        Field field = browserContent.getDisplayableContent();
        return(field);
    }
} 

 

Highlighted
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Loading a local html file in the browser

This worked for me with a little modification to the code which is in KB article.

 

 

try { InputStream input = getClass().getResourceAsStream("foo.html"); DataBuffer buffer = new DataBuffer(); byte[] temp = new byte[ 1024 ]; for( ;; ) { int bytesRead = input.read( temp ); if( bytesRead == -1 ) { break; } buffer.write( temp, 0, bytesRead ); } ByteArrayOutputStream output = new ByteArrayOutputStream(); Base64OutputStream boutput = new Base64OutputStream( output ); output.write( "data:text/html;base64,".getBytes() ); boutput.write( buffer.getArray() ); boutput.flush(); boutput.close(); output.flush(); output.close(); BrowserSession bSession = Browser.getDefaultSession(); bSession.displayPage( output.toString()); }catch(Exception e) { }

 

 

 


Use Search. "Accept Solution" If the problem is resolved.