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
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Packaging and accessing an HTML file in an application

My mistake, that is because I pulled the code form a running application, in that application it has a Repository class which keeps things like the standard application font.  So just remove that line.  It is not needed. 

Contributor
Posts: 31
Registered: ‎07-07-2010
My Device: 9630
My Carrier: Verizon

Re: Packaging and accessing an HTML file in an application

Thanks.  I removed that line and it did seem to compile with no issues.  The simulator launches but when I select the icon nothing is happening at all.  It does not even open the browser.  I suspect once again this is my lack if experience coming in to play. 

 

I took all the code you provided and added it to a new file in my project called BrowserOnlyScreen.java.  I believe (hope) that was the appropriate way to handle it.  Then I went back to my original code and added the line below as you mentioned, however now I am wondering if this line is even being executed since the browser is not launching.  Should I have placed this in the BrowserOnlyScreen.java module as well?  Again thanks for your time helping out a complete Java newbie.

 

BrowserOnlyScreen.displayLocalFileinBrowserScreen(​"myfile.htm");

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Packaging and accessing an HTML file in an application

Have you added the html you want to the project.  You need to do this otherwise the Browser can't find it.  And it needs to be called "myfile.htm".

 

If you make these changes you will get a Dialog box up indicating problems...

 

Before this line:

String ourhtml = new String(fileData);

 

Add
if ( fileData  == null || fileData.length < 1 ) {

Dialog.alert("File not found");

}

 

You will get a "File not found" dialog if the file has not been added, or not added correctly. 

Contributor
Posts: 31
Registered: ‎07-07-2010
My Device: 9630
My Carrier: Verizon

Re: Packaging and accessing an HTML file in an application

Added the code but still get no response and no browser launch when clicking on the icon in Downloads.  It is not even trying to start the browser at all for some reason, so not sure it is ever getting to the statements where it would attempt to read in the html file.  The file is added to the project in the same source folder as the .JAVA files.  Hopefully that is a valid location.

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Packaging and accessing an HTML file in an application

If you add the Dialog statement above, with different text, in various places, you should be able to 'debug' the processing by determining where it is actually getting to.  Before doing this I recommend you restore the base processing and so get it to the stage you used to have with it starting the Browser.

 

Is there anyone nearby that can read Java.  I suspect a very simple problem. 

Contributor
Posts: 31
Registered: ‎07-07-2010
My Device: 9630
My Carrier: Verizon

Re: Packaging and accessing an HTML file in an application

Unfortunately we don't have any Java types around.  I understand though if you can't assist any further given my lack of background on some of the basic techniques.  Everyone has been more than kind to offer help to this novice. 

 

Here is the code that worked before to get the browser launched when clicking the icon.  This code still launches the broswer if I leave it in there.  Obviously I was looking to display the contents of my HTML file and not the Blackberry home page, so other than the fact it pulls up the browser there is nothing else beneficial there for me.

 

 

       BlackBerryWebIcon webIcon = new BlackBerryWebIcon();
       webIcon.launchBrowser (DEFAULT_BROWSER, http://www.blackberry.com);
       webIcon.close();

 

 

Per earlier suggestion I had commented out these lines and replaced it with the statement below.  However in doing this the browser is no longer invoked when selecting the icon.  I don't know if I need a step prior to this to launch the browser before calling this new line or not, but it seems something is missing possibly. 

 

    BrowserOnlyScreen.displayLocalFileinBrowserScreen("myfile.htm");

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Packaging and accessing an HTML file in an application

Wasn't desperate for Java types, they would make your life a lot easier.

 

What we are trying to do here is launch the Browser, but inside your application.  So this does not interfere with anything else your users are doing externally in the Browser.  This would be best I think, and worth a little effort.  However it may be too much.

 

If you wish to continue to try this, then I would add Dialog statements, like the one I gave you earlier.  This will display a popup and so if you put these through out the code that should be executed, you can see how far it is actually getting. 

 

That said, there is an easier way.  This will use file i=within your application, but actually start the external however.  To reference a file in your application, you can just use this:

 

"cod://your code file name>/<your local file name>"

 

So if your cod was called com_mycompany_weburl and the file was test.html, then you would use, as the URL you were directing the  Browser to,

cod://com_mycompany_weburl/test.html

 

Having said this, I've not tested this mechanism for a while, and it might be worth the web kit browser (OS 6.0 and above) that they stopped supporting cod:.  In which case, replace the cod: with local: which I think they changed it to use.

 

As noted, I think it is better for your users if you get the BrowserField working, but the cod/local URL is probably easier for you.

 

Let us know how you get on

Contributor
Posts: 31
Registered: ‎07-07-2010
My Device: 9630
My Carrier: Verizon

Re: Packaging and accessing an HTML file in an application

Thnaks again.  I had seen that COD shortcut mentioned in searching for solutions.  I keep getting 404 File not Found errors when trying it (device software 5.x).  For sanity purposes can you verify this is how the statement should be formulated?  Just want to verify I am doing the right thing.  My COD file is called BlackberryWebIcon.COD and my html file is myfile.htm.  My statement is:

 

       BlackBerryWebIcon webIcon = new BlackBerryWebIcon();
       webIcon.launchBrowser (DEFAULT_BROWSER, "cod://BlackberryWebIcon/myfile.htm ");

 

As mentioned this does indeed pull the browser up, so that is good.  However I get the 404 error and the file never loads.  Because the browser was coming up here this is the same location I put the Browserfield call as well, unfortunately it never got as far as launching the browser.  As you mentioned though short of the COD shortcut working I will try and set some messages in the code so I cna try and figure out where the browserfield is bombing out.

 

Many thanks once again

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Packaging and accessing an HTML file in an application

Your URL looks wrong.

 

Refer back to my last post:

"cod://your code file name>/<your local file name>"

 

When you create a cod file, it has a name on the PC that you create - this name ends up on the PC with the extension .cod and it is this file that you will send to the BlackBerry when installing.  . 

 

This name, without the .cod, is what replaces

<your code file name>

 

Then you will have a file that you have added, this is the name that replaces

<your local file name>

 

You have coded:

"cod://BlackberryWebIcon/myfile.htm"

 

This would indicate that you have called you cod Blackberry/WebIcon, which is not valid.  So replace this with your actual cod name and see what happens.

 

Play round with this, and make sure you add your html resource at the same 'level' as your Java source, so there are no directories involved (I don't  think these directories impact the processing but let us have as few variables as we can.)

 

And remember that every character is significant, including the space you have at the end.  I would remove that. 

 

Good luck. 

Contributor
Posts: 31
Registered: ‎07-07-2010
My Device: 9630
My Carrier: Verizon

Re: Packaging and accessing an HTML file in an application

OK, so now I feel even more foolish (if that is possible).  It was just the extra space that was causing my issue with locading via the COD workaround.  Just removed the space and did a rebuild and it works just like I had hoped.  Now if I can just figure out how to package for the push out to a test device.  I think just COD and ALX files needed right?  I'll also have to figure out the possible imapct of device software 6 like you mentioned as we do have some of that.

 

I can't thank you all enough for the help on this.  You have been more than patient with someone not even knowledgable enough to be considered a newbie.  Greatly appreciated.