08-19-2009 08:23 AM
I am developing one native application which involves lots of file content. I can show the list of files. When I am opening the file content, the content should be shown in the browser. I can show the content in the browser as a separate instance. Can I embed the browser content in the Blackberry screen?
Hope this information helps!!
Thanks for any help.
Solved! Go to Solution.
08-19-2009 08:27 AM
08-19-2009 08:56 AM
simon_hain wrote:
take a look at the browserfield demo that ships with the jde
I think it's to demo the content in the browser and not for embedding the browser content in the screen.
Guide me on this.
Am I miss anything here?
08-19-2009 09:06 AM
08-19-2009 09:08 AM
09-30-2009 03:21 AM
BBDeveloper wrote:
As Simon suggested, browserfield demo is the one which will server your need.
I tried like the things in demo. Content is getting rendered. But, images are not showing and only broken images only coming.
public class ContentScreen extends MainScreen implements RenderingApplication { private ContentScreen contentScreen; private static final String REFERER = "referer"; private RenderingSession _renderingSession; public VerticalFieldManager contentManager = new VerticalFieldManager(VerticalFieldManager.NO_VERTI
CAL_SCROLLBAR); Event e; public ContentScreen(String url) { System.out.println("inside ContentScreen cons"); _renderingSession = RenderingSession.getNewInstance(); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(url, null, null, null, this); thread.start(); add(contentManager); } public void processConnection(HttpConnection connection, Event e) { System.out.println("inside processConnection processConnection"); BrowserContent browserContent = null; try { RenderingOptions renderingOptions = _renderingSession.getRenderingOptions(); renderingOptions.setProperty(RenderingOptions.CORE _OPTIONS_GUID, RenderingOptions.SHOW_IMAGES_IN_HTML, true); browserContent = _renderingSession.getBrowserContent(connection, this, e); if (browserContent != null) { Field field = browserContent.getDisplayableContent(); if (field != null) { synchronized (Application.getEventLock()) { contentManager.deleteAll(); //contentManager.add(new LabelField("This is for Testing the browser Content inside the screen")); contentManager.add(field); //contentManager.add(new LabelField("This is at th end of the content feild form the broswser ::::::::::::::::::::::::::::::::::::")); } } browserContent.finishLoading(); } } catch (RenderingException re) { System.out.println(e); } finally { SecondaryResourceFetchThread.doneAddingImages(); } } public Object eventOccurred(Event event) { System.out.println("inside eventOccurred"); int eventId = event.getUID(); switch (eventId) { case Event.EVENT_URL_REQUESTED : { UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event; String absoluteUrl = urlRequestedEvent.getURL(); HttpConnection conn = null; PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(urlRequestedEvent.getUR L(), urlRequestedEvent.getHeaders(), urlRequestedEvent.getPostData(), event, this); thread.start(); break; } case Event.EVENT_BROWSER_CONTENT_CHANGED: { // browser field title might have changed update title BrowserContentChangedEvent browserContentChangedEvent = (BrowserContentChangedEvent) event; if (browserContentChangedEvent.getSource() instanceof BrowserContent) { BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource(); String newTitle = browserField.getTitle(); } break; } case Event.EVENT_REDIRECT : { RedirectEvent e = (RedirectEvent) event; String referrer = e.getSourceURL(); switch (e.getType()) { case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT : // show redirect message Application.getApplication().invokeAndWait(new Runnable() { public void run() { Status.show("You are being redirected to a different page..."); } }); break; case RedirectEvent.TYPE_JAVASCRIPT : break; case RedirectEvent.TYPE_META : // MSIE and Mozilla don't send a Referer for META Refresh. referrer = null; break; case RedirectEvent.TYPE_300_REDIRECT : // MSIE, Mozilla, and Opera all send the original // request's Referer as the Referer for the new // request. Object eventSource = e.getSource(); if (eventSource instanceof HttpConnection) { referrer = ((HttpConnection)eventSource).getRequestProperty(R EFERER); } break; } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setProperty(REFERER, referrer); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(e.getLocation(), requestHeaders,null, event, this); thread.start(); break; } case Event.EVENT_CLOSE : // TODO: close the appication break; case Event.EVENT_SET_HEADER : // no cache support case Event.EVENT_SET_HTTP_COOKIE : // no cookie support case Event.EVENT_HISTORY : // no history support case Event.EVENT_EXECUTING_SCRIPT : // no progress bar is supported case Event.EVENT_FULL_WINDOW : // no full window support case Event.EVENT_STOP : // no stop loading support default : } return null; } public int getAvailableHeight(BrowserContent browserField) { return Graphics.getScreenHeight(); } public int getAvailableWidth(BrowserContent browserField) { // field has full screen return Graphics.getScreenWidth(); } public int getHistoryPosition(BrowserContent browserField) { // no history support return 0; } public String getHTTPCookie(String url) { // no cookie support return null; } public HttpConnection getResource( RequestedResource resource, BrowserContent referrer) { if (resource == null) { return null; } // check if this is cache-only request if (resource.isCacheOnly()) { // no cache support return null; } String url = resource.getUrl(); if (url == null) { return null; } // if referrer is null we must return the connection /* if (referrer == null) { HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null); return connection; }*/ return null; } public void invokeRunnable(Runnable runnable) { (new Thread(runnable)).run(); } class PrimaryResourceFetchThread extends Thread { private ContentScreen _application; private Event _event; private byte[] _postData; private HttpHeaders _requestHeaders; private String _url; PrimaryResourceFetchThread(String url, HttpHeaders requestHeaders, byte[] postData, Event event, ContentScreen application) { System.out.println("url of the document to be viewed ::::::::::: " + url); System.out.println("inside PrimaryResourceFetchThread"); _url = url; _requestHeaders = requestHeaders; _postData = postData; _application = application; _event = event; } public void run() { //HttpConnection connection = Utilities.makeConnection(_url, _requestHeaders, _postData); try { System.out.println("inside run"); HttpConnection connection = (HttpConnection)Connector.open(_url); //connection.setRequestMethod(HttpConnection.POST) ; _application.processConnection(connection, _event); } catch(Exception ex) { System.out.println(ex); } } }
Am I iss anything?
Thanks for any help.
09-30-2009 06:54 AM
It's working fine for me now. I made a mistake in the code.
Can I reuse the demo code in my application since it belongs to Blackberry?
Thanks.
09-30-2009 08:12 AM
11-04-2009 03:19 AM
I also have the same problem. So how you can show the image now ? Plz help me .
Thank you very much!
01-18-2010 03:58 AM
Hi BberryDev,
I am not able to render images on my screen.
Could you please help me how to accomplish this.
Thanks