Custom BrowserField appears in the real device Simulator only

Hey guys, I got some piece of code that I can use to display HTML data stored in a variable. It worked fine in the Simulator, but when I tried to view it on a real device (I use 8900), it shows nothing.

Here is the code (HTMLField.java): (I use the code here: http://supportforums.blackberry.com/t5/Java-Development/Display-HTML-in-a-Screen-Field/td-p/335074/p...)

package app;

import java.io.IOException;

import javax.microedition.io.HttpConnection;

import net.rim.device.api.browser.field.BrowserContent;
import net.rim.device.api.browser.field.Event;
import net.rim.device.api.browser.field.RedirectEvent;
import net.rim.device.api.browser.field.RenderingApplication;
import net.rim.device.api.browser.field.RenderingException;
import net.rim.device.api.browser.field.RenderingOptions;
import net.rim.device.api.browser.field.RenderingSession;
import net.rim.device.api.browser.field.RequestedResource;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.io.http.HttpHeaders;

/**
 * A field which displays HTML content.
 * @author Febiyan Rachman
 */
public class HTMLField extends VerticalFieldManager implements RenderingApplication
{
    private String data;
    private static final String REFERER = "referer";
    private RenderingSession renderingSession;
    private HttpConnection currentConnection;
    private Field field;

    /**
     * Default constructor
     * @param data
     */
    public HTMLField(String data)
    {
        this.data = data;
        renderingSession = RenderingSession.getNewInstance();
        // Enable JavaScript
        renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);
    }

    /**
     * Start parsing thread
     */
    public void parseHTML()
    {
        if(!data.startsWith("";
        HTMLFieldConnection thread = new HTMLFieldConnection(data, null, this);
        thread.start();
    }

    /**
     * Parse HTML
     * @param data
     */
    public void parseHTML(String data)
    {
        this.data = data;
        if(!data.startsWith("";
        HTMLFieldConnection thread = new HTMLFieldConnection(data, null, this);
        thread.start();
    }

    /**
     *
     * @param connection
     * @param event
     */
    public void processConnection(HttpConnection connection, Event event)
    {
        // Cancel previous request
        if (currentConnection != null) {
            try
            {
                currentConnection.close();
            }
            catch (IOException e1) {
            }
        }

        // Set the current connection to the created connection
        currentConnection = connection;

        BrowserContent browserContent = null;

        try
        {
            browserContent = renderingSession.getBrowserContent(connection, this, event);

            if (browserContent != null)
            {
                // Create a field which displays the HTML content
                Field newField = browserContent.getDisplayableContent();
                // Add field to this manager
                if (newField != null)
                {
                    if(field != null)
                    {
                        synchronized (UiApplication.getEventLock())
                        {
                            replace(field, newField);
                            field = null;
                            field = newField;
                        }

                    }
                    else
                    {
                        synchronized (UiApplication.getEventLock())
                        {
                            add(newField);
                            field = newField;
                        }

                    }
                }

                // Finish!
                browserContent.finishLoading();
            }
        }
        catch (RenderingException renderingException)
        {
            System.out.println("RenderingException : " + renderingException);
        }
        catch (Exception exception)
        {
            System.out.println("Exception : " + exception);
            exception.printStackTrace();
        }
    }

    /**
     * @see net.rim.device.api.browser.field.RenderingApplication#eventOccurred(net.rim.device.api.browser.field.Event)
     */
    public Object eventOccurred(Event event)
    {
        int eventId = event.getUID();

        switch (eventId)
        {
            case Event.EVENT_URL_REQUESTED:
            {
                HTMLFieldConnection thread = new HTMLFieldConnection(data, null, this);
                thread.start();
                break;
            }
            case Event.EVENT_BROWSER_CONTENT_CHANGED:
            {
                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 Referrer for META Refresh.
                        referrer = null;
                        break;
                    case RedirectEvent.TYPE_300_REDIRECT:
                        // MSIE, Mozilla, and Opera all send the original
                        // request's Referrer as the Referrer for the new
                        // request.
                        Object eventSource = e.getSource();
                        if (eventSource instanceof HttpConnection)
                        {
                            referrer = ((HttpConnection) eventSource).getRequestProperty(REFERER);
                        }
                        break;
                }

                HttpHeaders requestHeaders = new HttpHeaders();
                requestHeaders.setProperty(REFERER, referrer);
                HTMLFieldConnection thread = new HTMLFieldConnection(this.data, event, this);
                thread.start();
                break;

            }
            case Event.EVENT_CLOSE:
                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 browserContent)
    {
        return 0;
    }

    public int getAvailableWidth(BrowserContent browserContent)
    {
        return 0;
    }

    public String getHTTPCookie(String url)
    {
        return null;
    }

    public int getHistoryPosition(BrowserContent browserContent)
    {
        return 0;
    }

    public HttpConnection getResource(RequestedResource resource, BrowserContent referrer)
    {
        return null;
    }

    public void invokeRunnable(Runnable runnable)
    {
    }

}

BrowserApp.java

package app;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * @author Febiyan Rachman
 */
public class BrowserApp extends UiApplication implements FieldChangeListener
{
    HTMLField htmlField;
    EditField textField;

    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        BrowserApp app = new BrowserApp();
        app.enterEventDispatcher();
    }

    /**
     * Default constructor
     */
    public BrowserApp()
    {
        MainScreen screen = new MainScreen();
        screen.setTitle("Browser Test");
        htmlField = new HTMLField("");
        //screen.add();
        textField = new EditField("Tes : ", "");
        ButtonField button = new ButtonField("click", ButtonField.CONSUME_CLICK);
        button.setChangeListener(this);
        screen.add(textField);
        screen.add(htmlField);
        screen.add(button);
        pushScreen(screen);
    }

    // parseHTML and display it
    public void fieldChanged(Field field, int context)
    {
        // TODO Auto-generated method stub
        htmlField.parseHTML(textField.getText());
    }

}

HTMLFieldConnection.java

package app;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.HttpConnection;

import net.rim.device.api.browser.field.Event;

public class HTMLFieldConnection extends Thread implements HttpConnection
{
    private long streamLength = 7000;
    private DataInputStream dataInput;
    private InputStream in;
    private String encoding = "text/html";
    private HTMLField htmlField;
    private Event event;
    private String data;

    /**
     * Default
     * @param data
     * @param event : event object for eventOccured() function
     * @param htmlField : HTML display field
     */
    public HTMLFieldConnection(String data, Event event, HTMLField htmlField)
    {
        this.data = data;
        this.htmlField = htmlField;
        this.event = event;
    }

    public String getURL()
    {
        return "";
    }

    public String getProtocol()
    {
        return "";
    }

    public String getHost()
    {
        return "";
    }

    public String getFile()
    {
        return "";
    }

    public String getRef()
    {
        return "";
    }

    public String getQuery()
    {
        return "";
    }

    public int getPort()
    {
        return 0;
    }

    public String getRequestMethod()
    {
        return "";
    }

    public void setRequestMethod(String s) throws IOException
    {

    }

    public String getRequestProperty(String s)
    {
        return "";
    }

    public void setRequestProperty(String s, String s1) throws IOException
    {

    }

    public int getResponseCode() throws IOException
    {
        return 200;
    }

    public String getResponseMessage() throws IOException
    {
        return "";
    }

    public long getExpiration() throws IOException
    {
        return 0;
    }

    public long getDate() throws IOException
    {
        return 0;
    }

    public long getLastModified() throws IOException
    {
        return 0;
    }

    public String getHeaderField(String s) throws IOException
    {
        return "";
    }

    public int getHeaderFieldInt(String s, int i) throws IOException
    {
        return 0;
    }

    public long getHeaderFieldDate(String s, long l) throws IOException
    {
        return 0;
    }

    public String getHeaderField(int i) throws IOException
    {
        return "";
    }

    public String getHeaderFieldKey(int i) throws IOException
    {
        return "";
    }

    public String getType()
    {
        return "text/html";
    }

    public String getEncoding()
    {
        return encoding;
    }

    public long getLength()
    {
        return streamLength;
    }

    public InputStream openInputStream() throws IOException
    {
        return in;
    }

    public DataInputStream openDataInputStream() throws IOException
    {
        return dataInput;
    }

    public void close() throws IOException
    {

    }

    public OutputStream openOutputStream() throws IOException
    {
        return new ByteArrayOutputStream();
    }

    public DataOutputStream openDataOutputStream() throws IOException
    {
        return new DataOutputStream(new ByteArrayOutputStream());
    }

    public void run()
    {
         try
         {
             in = new ByteArrayInputStream(data.getBytes("UTF-8"));
             dataInput = new DataInputStream(in);
         }
         catch (Exception e)
         {
             System.out.println("HttpConnectionImpl : Exception : " + e);
         }
        this.htmlField.processConnection(this, this.event);
    }
}

Is there something wrong with it?

Yes, as I finally tried again and again, it seems that the OS 5 does not support old stuff like that, it has its own browserfield2.

Tags: BlackBerry Developers

Similar Questions

  • How to develop and test the application mobile flex without the real device?

    I'm trying to read some information about it, but decided to ask also here.

    I have a project that has a company wants to grow me, it's for iPad. That's ok I am with Flex and the framework for web development, but not for mobile. Why? Because I have no idea how to test my application. I know generation ago it sort of the desktop version of the application with the change of the "back" button on the orientation stuff, but how do I know my application will look and work exactly the same (I mean NOT performance here). I mean you know how every android or iOS device have their native keyboard or native video player for example and I have only in the debug version of the application.

    The question is how to develop this application based on the desktop emulator or anything and then hope that my app looks and works on a device, as it should... Of course I can't afford to buy all the devices it is just to be able to test on it if necessary? So, how do you, how to test how my iPad app works on a device without a? I know I should get a licence from iOS dev to be able to package the app for iOS, but it's $ 99 per year or something like that I can handle, but how to test my application without having to buy the darn device? Are there any emulator for iPad or something like that I know what my customers will see when they get the application? One of my friends told me that the mac os x use the developers a tool - cause some kit of dev who has emulators for all iOS devices and you can build and test there immediately and that you can simulate virtually any combination of key for example, and he said he's working and seems to 1:1 as the real device but he didn't know if can I export an AIR application and try it like this, he only knew for app written in native code.

    If someone can just tell me how should I do this? Should I buy a mac os x computer laptop to test because I am a user of windows 7, or perhaps create a mac os x virtual machine and tests out there or maybe the only option is to actually buy the device... that would be terrible for a freelancer...

    I hope someone can save the day here! Thank you.

    F

    Since the AIR for iOS applications are compiled to ARM code you will not be able to run on iOS emulators running on Mac OSX.

    You can do a very simple test with the "Simulator" built into Flash Builder, but it is not much more than a window to AIR with a window size that matches the resolution of the selected iOS device.  When running in the simulator of the application is not compiled to ARM code so it will take a completely different code path than what will be the final release of iOS.

    Ultimately if you are developing for iOS with AIR nothing but for tests on real iOS devices.

  • My HDMI cable does not appear in the reading devices or Device Manager. I need to fix this problem

    My HDMI cable does not appear in the reading devices or the Device Manager even if it is plugged, the problem is I want to play sounds through my TV that is connected using the HDMI interface. He appeared once in the playback devices and I allowed and played on a YouTube video and it slowed down the video and the sound was stuttering.  Does anyone know how to fix this? If you do then I would like to thank you in advance.

    Hello

    I suggest you try the steps from the following link and see if that helps.
    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-pictures/Windows-7-cant-get-HDMI-audio-the-HDMI-device-does/a494af37-9780-4b4a-895C-b2c1fce17fe6

    I hope this helps. Let us know if you have other problems with Windows in the future.

  • BrowserFieldAPIDemo application does not work on the real device

    Hello

    anyone tried the demo of browserfieldapi running on a real device? When I try to run on the real device, it shows a white screen.

    Thank you


  • scroll bar appears in the BlackBerry device

    Hello

    I did a single application in which I show web service data in the table with the scroll bar. but in fact when I run the simulator of scroll bar appears. but when I run the scrollbar device not shown. I used JavaScript to display the table.

    Help, please

    Simulator and device operating system is the same?

  • Push the message undeliverable to the live Device - Simulator (Eclipse) works

    My app works great on different simulators, receive messages from my server (all on localhost). However, I can't make it work when I plug in my phone via USB. I select my phone in the list of Blackberry devices and then installs the application, starts the listener in the background and I can open the user interface. Messages are delivered to the MDS, but they then fail with the message:

    PushServlet: FAILURE - cannot map device XXXXX a host to the PDAP.

    I tried to add my device Simulator "rimpublic.property" section, but that didn't work either: I think that it comes to queue messages.

    Any advice?

    Thank you

    Karl

    I found the answer. It is the combination of two things:

    (1) I had to use 'ApplicationManager.getApplicationManager () .inStartup ()' to delay my code from running until the aircraft was ready.

    (2) I tried to debug using my direct phone with an SDM server on my laptop (localhost). I never had this work, but once I opted for the reality of the BES server, the debugger kicks and everything worked as expected.

    Karl

  • Custom Store Front in the Android device generation with store_configurator are not displayed on V31

    Build Custom Store Front on Android device with https://www.dpsapps.com/dpsapps/store_configurator/ and incorporated in V31 android native App print an empty screen.

    To reproduce:

    -Build a custom store front https://www.dpsapps.com/dpsapps/store_configurator/

    -Load the ZIP file of stores personalized with https://appbuilder.digitalpublishing.acrobat.com/#/main

    in your application

    -Build your app and open it

    RESULT: I have my app logo on the upper left corner of the header of the app, but nothing seems less, it looks like HTML is loaded because the background color is set correctly, but not more...

    Tested on Galaxy TAB 10.1 GT-P7510 Android 4.0.4

    It is a known problem with the code generated by the Configurator on this version of Android. In the custom code store search the main.js file and replace the jsFilese var and lines of css var by the following:

    var jsFiles = [path + "js/app.js",
    path + "js/controllers.js,"
    path + "js/services.js,"
    path + "js/directives/folioItemView.js."
    path + "js/directives/indeterminateProgressBar.js."
    path + "js/directives/mainFolioView.js."
    path + "js/directives/tabBar.js."
    path + "js/directives/tabContentContainer.js."
    path + ' js/Config.js'];

    var css = path + 'styles.css ';

    Neil

  • EventLogger events does not appear in the event log Simulator

    So, I was more than a little frustrated with debugging Widget applications and decided to help me a bit.

    I've created a Widget extension that connects to System.out and the EventLogger BB using:

    Logger.Java:

    public class Logger {}

    public static final String APP_NAME = "AppName";
    public static final long GUID = 0xb50dd37e31148effL;

    public static enableLogging() Sub {}
    If (EventLogger.register (GUID, APP_NAME, EventLogger.VIEWER_STRING)) {}
    out ("recorder active.");
    }
    else {}
    ("EventLogger record has failed.");
    }
    }

    /**
    * Prints System.out and event log (if enabled).
    */
    public static {Sub out (String msg)
    String message = formatMessage (msg);
    System.out.println (message);
    log (message);
    }

    /**
    * Prints in the journal of the events with the ALWAYS_LOG level.
    */
    Public Shared Sub log (String msg) {}
    logEvent (msg, EventLogger.ALWAYS_LOG);
    }

    private public static Sub logEvent (String msg, int level) {}
    If (EventLogger.logEvent (GUID, msg.getBytes ())) {}
    System.out.println ("EventLogger.logEvent succeeded.");
    }
    else {}
    System.out.println ("EventLogger.logEvent failed.");
    }
    }
    ...
    }

    The Widget extension works.  I can not even log JavaScript stuff :

    somewhere in file.js:

    Logger.log ("it is JavaScript!");

    as seen by the Eclipse debug console:

    AppName [2010-09-24 12:01:33.609]: active recorder.
    EventLogger.logEvent succeeded.
    AppName [2010-09-24 12:01:33.625]: it's JavaScript!
    EventLogger.logEvent succeeded.

    RIDDLE ME THIS: WHY are the messages NOT sent to the event log Simulator! (9550 or 9800 > tools > Show Event Log does not show my posts.)

    My frustration with BB Monte.

    -----

    Windows XP 32-bit

    Install Eclipse Version: 3.5.2 version identifier: M20100211-1343

    Version plugin Web blackBerry: 2.0.0.201003191451 - 33

    BlackBerry Java plug-in Version: 1.1.2.201004161203 - 16

    BlackBerry Java SDK Version: 5.0.0.25
    BlackBerry Widget SDK Version: 1.0.0.201003191451 - 126

    6.0.0.141 blackBerry SmartPhone Simulator

    As a new BB developer, imagine my surprise when I discovered that the API of EventLogger BB and the BB Simulator event log were completely foreign.

    It's like they're really trying to confuse us.

  • Google Maps showing is not the real device...

    Hi all

    I use third party API for google maps on BlackBerry. I downloaded the library card from the link below.

    http://www.nutiteq.com/MGMaps-lib-SDK-downloads

    The app works very well and the cards are displayed in the Simulator, but when it is deployed on

    real aircraft, the map is displayed in red. I use Wi-Fi for internet and I use

    BlackBerry 8520 device and BB Java Plug in for Eclipse.

    Please help me, very important in my project.

    Kind regards

    Saran.

    Hi Simon,.

    Thanks for your reply, I solved my problem and its working fine now.

    Kind regards

    Saran.

  • Why NEITHER cDAQ-9178 isn't in the DAQmx device simulated in MAX?

    Hi all

    I want to create a device that simulated for cDAQ-9178. But Max, I could not find it. It lists only NOR cDAQ-9172. I have the version of NOR-DAQmx 8.9.5.

    Thank you

    Raja

    LV 2009

    Hello Dennis,.

    NEITHER cDAQ-9178 is listed under DAQmx 9.0.2 supported device.

    Thank you

    Raja

  • Impossible to get data of Httpconnection and analyze these data on the real device

    Hello

    I use a Blackberry 9000 "BOLD" device. I get xml using the Http connection. My Simulator, it works fine. (Note that I'll have to keep MDS - CS run in HTTP request).

    but when I install the application on the device it shows only the UI elements. No data is downloaded from HTTP connection.

    Do I have to apply all the settings on the device? Please suggest.

    Thank you

    Aktaion.

    Make sure that properly define the connection string.

    There is a very good guide here: http://www.localytics.com/blog/post/how-to-reliably-establish-a-network-connection-on-any-blackberry...

  • BlackBerry Smartphones Enterprise activation screen appears when the unlocking device...

    It started to happen about 6 of my users. When they unlock their 8900's that the Enterprise Activation screen appears (with no informed information) run us BES5.0 and these devices have been activated for at least 12 months. No money changers have been made to the server or policy in more than a month. Everyone knows this? Obviously all what they need to do is to close it, but then it comes back the next time that they unlock the device. Thanks, Edd...

    I just found this course to blackberryforums, it seems that a reactivation of the unit does not seem to solve the problem... I'll give it a try later today if I have time, TGIF!

    http://www.BlackBerryForums.com/BES-Admin-corner/215863-all-my-BlackBerry-devices-now-getting-random...

  • iMessages appear on the wrong device

    Bought a new phone Friday, restored from a backup.

    the next day, I have my child and the text is appeared on my wife's phone to text. It was not a group text but was treated as a single.

    I'm sure that somewhere along the implementation of the new phone, something got confused, but no idea what.

    So, how can I keep the third text ungrouped?

    Two of the phones are on iOS 9, the third is about 8.4 or 9.x (not 9.2).

    Thank you.

    Hello

    I would recommend that you go to:

    General > Messages > sending & receiving > then check that the information is correct.

    I hope this helps.

    Jack

  • HP ENVY 15 notebook PC: HP ENVY 15 CDDVDW SN-208DB does not appear in the storage devices. Windows 7 Pro 64 bit SP 1.

    Help!

    My system doesn't see my optical drive from the "Computer" desktop icon

    Device Manager sees the drive.

    The drive snaps into rotation at boot time.

    When I insert a CD/DVD, the disc spins for a few seconds, the Green LED flashes.  Nothing else happens after that.

    Troubleshooting:

    1. update the firmware of HHO1 attempt. "This version not taken in charge." Failed.

    2. optical drive uninstalled, reinstalled driver. Failed

    3. disabled/enabled the player optical inDevice Manager. Failed

    4. unable to locate the correct driver on the net. Toshiba/Samsung website is not the good driver available. Failed.

    5. I have BIOS F.66. Flashed the BIOS. Failed.

    The last time this happened, I did a fresh install of factory and it worked.

    This time, it did not help.

    Any help to solve this problem would be would be greatly appreciated.

    Thank you

    Bruce

    Hello:

    See if you perform one of the tips of resolution at the address works.

    https://support.Microsoft.com/en-us/KB/314060

    Resolution No. 5 works normally, in the case of the player not listed is not in 'computer '.

  • The HP devices displays only not properly in web jetadmin

    HOSTS 10.3.8810 - we have moved to a new location (network managed by a different group) and our digital senders appear as hp_mgmt_printer_120 devices, and our CP4525s CLJ appears as CLJ 3700 s. Cannot show details for devices and manage them. You can add a device, a green success message "device found", but you can't do anything with them. They have the status of peripheral communication error, the firlds appear as . The networking guys claim that they are not blocking snmp. I installed HOSTS on my Win7 x 86 box and on a x 64 server - same question W2K8R2. (on a network different I installed it on a win7 x 86 and it works fine, so I'm sure I'm not doing something stupid during installation)

    Help!

    FIPS. Death to the FIP.

    GRRRR.

Maybe you are looking for