Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As <a href="http://docs.blackberry.com/en/developers/deliverables/11958/Display_HTML_from_a_resource_within_your_app_825672_11.jsp" rel="nofollow noreferrer">the link that @Turdnugget supplied</a> says: </p> <blockquote> <p>The BrowserField class does not access resources using a folder structure. The BrowserField class displays the first resource found that matches the specifed file name. </p> </blockquote> <p>That means that even if you put index.html into an <code>assets</code> folder, the BlackBerry build process and/or runtime will <em>flatten out</em> (i.e. ignore) your directory structure and therefore you'll have to load the html file with:</p> <pre class="lang-java prettyprint-override"><code>myBrowserField.requestContent("local:///index.html"); </code></pre> <p>As you can imagine, this works ok if you only have one file named <code>index.html</code> in your project, but if you have two files with that name, in different folders, the browser field may not load the one you want. I have projects where I do have different versions of html files that are loaded depending on the device, or the version of the app (full vs. free). So, I like to be able to store my html resources in different folders. </p> <p>To accomplish this, I've used the following code with <code>BrowserField</code>:</p> <pre class="lang-java prettyprint-override"><code> browser = new BrowserField(); add(browser); InputStream content = getClass().getResourceAsStream("/resourcesWeb/index.html"); try { byte[] html = IOUtilities.streamToBytes(content); browser.displayContent(new String(html), "http://localhost"); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>For this to work, I store the file <code>index.html</code> in a folder named <code>resourcesWeb</code> (name it whatever you like), and that folder is located inside the top-level <code>res</code> folder.</p> <p>Note that this is not Android. There is not normally an <code>assets</code> directory. When you use the BlackBerry Eclipse plug-in to create a new project, it creates a <code>src</code> and a <code>res</code> folder for you. I would use that. Create a new project if you need to. Then, keep all non-source code resources (html, xml, images, etc.) somewhere under the <code>res</code> folder.</p> <p>If you didn't create your project this way, you may find that your app is built without including the <code>assets</code> folder you created. You can <em>probably</em> fix this by right clicking on your project in Eclipse, and selecting <strong>Properties</strong>. You can add the <code>assets</code> folder to the Build Path using this dialog:</p> <p><img src="https://i.stack.imgur.com/tzXDz.png" alt="enter image description here"></p> <p>and notice that <code>assets</code> should show up in the <strong>Order and Export</strong> tab as well. </p> <p>However, I think it's easiest just to create and use projects the way the BlackBerry Eclipse plugin wants to. This will also make your projects more familiar to other BlackBerry Java developers that see your code. In my opinion, you should save Android naming conventions for Android projects.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload