Help with a simple StreamConnection to retrieve HTTP content

Hi all

I'm new to the BlackBerry development and tries to retrieve the content of a Web site and exit in a RichTextField, based on the example provided in the BB Developer's Guide. The code snippet I tested is below, but when I click on the app in the Simulator, nothing happens (it stays on the screen for downloads). Subscribe to the code of connection allows me to display the application user interface.

class MyProgramClass extends MainScreen {

    public MyProgramClass() {
        super();
        String progTitle = "My Program\n\n";
        setTitle(new LabelField(progTitle, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));

        RichTextField myField = new RichTextField();
        add(myField);

        try {
            StreamConnection streamConn = null;
            String myURL = "http://www.google.com/";
            streamConn = (StreamConnection) Connector.open(myURL);

            InputStream contentIn = streamConn.openInputStream();
            byte[] data = new byte[256];
            int length = 0;

            StringBuffer raw = new StringBuffer();
            while ( -1 != (length = contentIn.read(data)) ) {
                raw.append(new String(data, 0, length));
            }

            myField.setText(raw.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

I thought that it might be necessary to simulate next to the MDS emulator, but I managed to get the response of a given URL code so I guess that the connection is not not a question.

I understand that it would be preferable to apply it in a separate thread, but I don't think that this would be necessary, as a simple test? My environment is the most recent (since last week) SDK and BlackBerry plugin for eclipse and the 5.0 Bold 9700 simulator (apps: 5.0.0.535).

Any help would be greatly appreciated

Thank you

Will be

You must specify whatr type of connection you will use: change your code for:

public class MyProgramClass extends MainScreen {

    public MyProgramClass() {
        super();
        String progTitle = "My Program\n\n";

        setTitle(new LabelField(progTitle, LabelField.ELLIPSIS
                | LabelField.USE_ALL_WIDTH));

        final RichTextField myField = new RichTextField("Waiting for google.com...");
        add(myField);

        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                try {
                    StreamConnection streamConn = null;
                    String myURL = "http://www.google.com;deviceside=true";
                    streamConn = (StreamConnection) Connector.open(myURL);

                    InputStream contentIn = streamConn.openInputStream();
                    byte[] data = new byte[256];
                    int length = 0;

                    StringBuffer raw = new StringBuffer();
                    while (-1 != (length = contentIn.read(data))) {
                        raw.append(new String(data, 0, length));
                    }

                    myField.setText(raw.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                    myField.setText(e.toString());
                }

            }
        });

    }
}

And check out the http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Tags: BlackBerry Developers

Similar Questions

  • Need help with a simple basketball game.

    Hi im new here and I need help with what makes this simple basketball game.

    Im trying to recreate this this video game. I'm not sure if it uses as2 or as3

    If someone could help me make a game like this or point me to a link on how to do it would be greatly appreciated.

    AS2 is used in the video.  If you have other issues, please post in the forum AS1/AS2.

  • Please help with some simple AS2

    Hello

    I have a puzzle that I adapted in AS2. It is perfect for my needs, with one exception. It has a 'Start' button that erases the image of the puzzle, so you can start to assemble. I don't need the 'Start' button and am currently placing the script from the 'Start' button in the timeline, so that the picture of the completed puzzle is automatically cleared, ready to start assembling the four parts. The code original source from headache and Tunis is located here:

    http://www.ActionScript.org/resources/articles/13/1/jigsaw-puzzle/Page1.html

    This is the script that is currently on the button:

    We (Release)

    {

    for (i = 1; i < = n; i ++)

    {

    ["p" + i] this.joined_mc ._visible = false;

    }

    }

    and the button is inside a clip on the main stage.

    Please can someone help me on this point - would be really grateful!

    Thank you

    Ed.

    If it's a simple button (not a movieclip button) and attach the button containing the chronology:

    for (i = 1; i<>

    {

    ["P" + i] this.joined_mc ._visible = false;

    }

  • Please help with installing simple label

    Hi guys,.
    I know that it will be simple for most of you. Used good ol PageMaker ' years. Has started with the ID of a couple of years, but have not made a lot with it. Now have CS6 and I wanted to address labels [Avery 5160 - 30 labels/page]. I remember this question once before w/CS3 and people said I had need of a later version that would allow me to 'merge' repeated on the page of the label without having to duplicate the text and graphics 30 times.
    Could someone give me the specific steps to follow to do this? It's all there in the original label of text and graphics. How I can repeat this 29 times without going through the bureaucracy to fool the text & chart [I did ].
    What I did was, group the text and graphic, it fool 2 times in a row, then fool the line again and again until the page was filled with 30 labels.
    Yes, I know I am a fool, and in "pain repetition" but having been a member of Adobe forums since the 90's I LOVE FORUMS! We all have helped so much. And that's where I get my answers.
    Thanks in advance,
    Ellen

    Printing labels on a personal printer can be a little tricky because the paper is sucked in most home printers, there is a bit of drift. What I mean is that if you print multiple copies of something in a paper stock that had graphic top brands, you will see that you cannot ensure that each sheet is printed in exactly the same position. For this reason, you'd better not try to print too close on the edges of each label. What I recommend is that you set up 30 text blocks and them all together in the string or use the fusion of data to set up your labels, you apply a line of half a percentage point for executives, print a map and see how close frames line up with the edges of your labels. You need to maybe move the Group of labels to the top, bottom, left, or right to bring it in the stadium, but once you set for your printer, you can take off the lines and define a quantity of text box so that if they drift a little, none will be cut off.

    Also, when you ask about it, you can select a single object or group and go to Edit > step and repeat and check the boxes create as a grid and Preview to 30 labels off alone and see how they will lay in the page. Just put your horizontal and vertical offset to the size of your label.

    Is that help, or do you need instructions on how to do a data merge?

  • Help with 2 simple scripts

    I am looking for 2 very simple scripts, we're for a specific cluster 1, I want to list all the VMS that have 4 GB of memory or more.

    Then a 2nd script for a specific cluster1, want to list VM which do not have the VM tools installed or are out of date and select the name, the tool vmware status and memory.

    Can someone help please

    Here is a line that I tried on a single host... and must work if you connect on a VC as well... people it will list all virtual machines with more than 4 GB of memory:

    Get - VM | Where-Object {$_.} MemoryMB - gt 4096}

    If you want just the name and memory, then:

    Get - VM | Where-Object {$_.} MemoryMB - gt 4096} | Select Name, MemoryMB

    For the other for the VMtools...

    Get-VM | Get-View | Select-Object @{N="Name";E={$_.Name}},@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
    

    Concerning

  • Need help with a simple calculation.

    I will apologize to the front. I have no knowledge of writing Javascripts. I can use them if someone writes to me, but that's all. I created a simple form with money dealing. I have boxes of different text for the user to enter a number based on what type of coin it is.Currency.jpg

    In the left column, they will enter a number. I would like for the right column counting from that. However, the quantity of money (ie. 100, 50, 20, etc.) is not a text field. It is simply the text entered in another program. I'm looking for is a way to do this without having to do the amounts in currency a text field. Something along the lines of X * 100 is.

    If you can give any help or suggestion, I'd be very happy.

    Thank you.

    You will have to hard code the quantity of money in the script.

    In the first line, create 2 text, Text1 and Text2 fields. Use what the calculation script personalized to Text2:

    If (this.getField ("Text1") ".value! == ' ') {}
    This.getField("Text1").value = Event.Value * 100;
    }

    Clears Text2 if nothing is in Text1
    else event.value = «»

    The second pair of text fields would be "50" instead of "100" in line 2, etc.

  • Need help with the Simple Question of coding (substring or charAt())

    Hello

    I have what I believe to be a simple matter of coding I was hoping that someone could help answer. I know how to do a decent amount of things but I'm pretty new to Livecycle and trying to change one of our PDF files so that if a certain field has a number starting with number 6 a certain button will become visible. I already have a set of code which is to control the visibility of this button, but I wanted to add this clause. Can someone help me to do this?

    Here are the existing code:

    If ((QuestionsPage2.COIQuestions.COIYN.rawValue == "1" & &))

    QuestionsPage2.EmailButtons.NSFCheck.rawValue == '1') & &

    (QuestionsPage2.ManagerSignature.ManagerDate.rawValue! = null & &)

    QuestionsPage2.ManagerSignature.ManagerCheckBox.rawValue! = null & &

    QuestionsPage2.ManagerSignature.ManagerSignature.rawValue! (= null))

    {

    QuestionsPage2.PasswordSection.RiskPassword.presence = "visible";

    QuestionsPage2.PasswordSection.PurchUseOnly.presence = "visible";

    QuestionsPage2.PasswordSection.HRPassword.presence = "visible";

    QuestionsPage2.EmailButtons.EmailContractsAndRisk.presence = "visible";

    }

    I would like to add at the top to look at the specific area of the first character to see if it is a 6 or not. Here's what I tried to do, but it did not work.

    If ((QuestionsPage2.COIQuestions.COIYN.rawValue == "1" & &))

    QuestionsPage2.EmailButtons.NSFCheck.rawValue == '1' & &

    ContractInfo.AgreementDetails.Org.substring (0.1)! = '6' )

    The type of field, that I'm looking is a field "Digital field" 4 characters.

    Can someone help me fix my code to make it work?

    Thank you!!

    you don't need to make such a work autour, everything you did not notice, this is NumericField isn't a string is always a numeric (number)

    If you can use substring on a whole or decimal number... unless it's a chain... then use the toString() after the .rawValue like this

    ContractInfo.AgreementDetails.Org. rawValue.toString (). Substring (0.1)! = « 6 »

    It should work.

  • help with a simple user interface for video flv with benchmarks AND buttons

    Hi all

    OK, I built a very simple FlashDrive using the componet video and I used in the flv file cue points, then I used simple buttons and findcuepoints code snipets for make my buttons go to a certain part of the movie.

    Everything works very well.

    Now what I do is when a certain amount of point play button stay an overstate and once made part of the video or another button is clicked on the first North of the State and the new part back button or the new button have the overstate.

    I think it will be an easy task, I'm not sure how to in this regard.

    Any help greatly appricaited.

    code below

    start_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint);
    
    function fl_ClickToSeekToCuePoint(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch1");
        vid.seek(cuePointInstance.time);
    }
    
    
    ch2_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint_1);
    
    function fl_ClickToSeekToCuePoint_1(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch2");
        vid.seek(cuePointInstance.time);
    
    }
    
    ch3_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint_2);
    
    function fl_ClickToSeekToCuePoint_2(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch3");
        vid.seek(cuePointInstance.time);
    }
    
    ch4_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint_3);
    
    function fl_ClickToSeekToCuePoint_3(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch4");
        vid.seek(cuePointInstance.time);
    }
    
    ch5_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint_4);
    
    function fl_ClickToSeekToCuePoint_4(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch5");
        vid.seek(cuePointInstance.time);
    }
    
    ch6_btn.addEventListener(MouseEvent.CLICK, fl_ClickToSeekToCuePoint_5);
    
    function fl_ClickToSeekToCuePoint_5(event:MouseEvent):void
    {
        var cuePointInstance:Object = vid.findCuePoint("ch6");
        vid.seek(cuePointInstance.time);
    }
    

    I try to help, but you will need to apply your neurons to make it work with what I have already explained (three times with what I propose below).  Try something like the following (I'm rename your buttons for ch1, ch2, ch3, ch4, ch5 and ch6 so that the same functions can be shared by all the buttons...)

    This affects the listeners to all 6 buttons

    for (var i: uint = 1; i<7;>

    This ["ch" + String (i)] .addEventListener (MouseEvent.CLICK, fl_ClickToSeekToCuePoint);

    }

    It deals with one of the 6 inclinometer when they are clicked

    function fl_ClickToSeekToCuePoint_1(event:MouseEvent):void

    {

    BTN var = event.currentTarget;

    var cuePointInstance:Object = vid.findCuePoint (btn.name);

    VID. Seek (cuePointInstance.Time);

    resetButtons();    What makes all the buttons back to normal

    btn.upState = btn.overState; What makes the States of change of the button clicked

    }

    function resetButtons (): void {}

    for (var i: uint = 1; i<7;>

    This ["ch" + String (i)] .upState = this ["ch" + String (i)] .hitTestState;

    }

    }

    To do this, your buttons need to have the same work as part of hit as they do under the top.

  • Help with a simple break-code function

    For a week I tried to understand a simple break-code function fror AS 3.0. I need something that makes a break as a code of a set amount of time. People have tried to help me on this forum, but I have not always been able to make the code work.

    Here's what I have in this moment of pause-code (does not work):

    var intID;
    intID = setInterval (delay, 3000); This tells flash to wait 3 seconds
    delay() {} function
    clearInterval (intID);
    _root.gotoAndPlay (1); or do something else...
    }

    The person who provided me with this code did not include the first line 'var intID', but as a new user of flash, I wasn't sure how else to declare intID. Could someone with some flash experience to guide me through the steps of creating a pause-code function or add to what I have already provided. When I use the code above in my flash document, the pause feature does not work. Essentially, he jumps on the setInterval and clearInterval functions only and cheek element root in delay(). I need code for AS 3.0 and I'm getting more and more desperate for an answer.

    I hope it's understandable and I thank you for taking a peek
    Sam

    This isn't code as3.

    Use the timer class to delay the execution of code in a function.

  • I need help with something simple [How do I Center my webpage?]

    Hello

    I followed the lessons to make my own site. I managed (with the help of you all) but I have a stupid thing that I can't understand. How do I Center the page 1000px. I have now with each thing on the left.

    small page.png

    The 1000px width setting (any id, class or element that has put on in your css), where to add in the next "BOLD" song...

    {#whatever_id}

    Width: 1000px;
    others: attributes;
         Auto margin: 0;

    }

  • Need help with the simple action

    I want to create an action in Photoshop when I return in the next layer and goe later in the previous layer, using shortcuts:

    ALT +]

    [Alt +]

    However, I am Danish and my keyboard using Alt + 9 to create a [ ]

    So I can't create my action... perhaps a kind soul could record this action and post it here?

    (You can also send to me, if that's easier. My address is kasperhviid Insert the @ here gmail.com)

    Hey Kasper,

    Always happy to help a developer to other actions...

    http://Noel.ProDigitalSoftware.com/ForumPosts/For_Kasper.zip

    Recorded in Photoshop CC.  Let me know if you need saved in an older version.

    -Christmas

  • help with a simple batch file to open files or folders in command prompt

    Read the article HERE. It should guide you to accomplish what it is you want.

    @ Daavee... I am a supporter of the Holiday Inn Express. I feel always smarter after a stay... hahaha

    OP.

    Use the following syntax to open a folder

    Start "" "File path".

    Example: start "" "C: \Documents and Settings\ username to open \My Documents\File name.

    The article HERE can be useful too.

    "No, I do not use the batch files. Just thought I'd share with you what I know. :-)"  Thanks again Daavee

  • Need help with a simple technique

    I use CS4 on Mac. It's my image:

    Screen Shot 2014-12-12 at 10.14.40 AM.png

    It is 9 tiles in distinct, although I don't know if that's relevant or now.

    The turquoise color is a solid turquoise path that lies at the back of the stack on each tile. I have the inside of the diamonds or the contours of the petals in his own way, so that I can introduce a new color. In other words, turquoise diamond contours interiors/white petal, or vice versa.

    What is the technique to do this?

    Mary,

    How about live paint?

    http://www.Graphics.com/article-old/Illustrator-fundamentals-live-paint

  • Need help with a simple regular expression replacement

    Hello everyone,

    He comes to the table that I have to work with.
    CREATE TABLE "TBL_ACCOMMODATION" ("ACCOMMODATION_ID" NUMBER, "HOTEL_NAME" VARCHAR2(100), "ADDRESS" VARCHAR2(200), "LOCATION" VARCHAR2(100), "PHONE" VARCHAR2(50), "EMAIL_ADDRESS" VARCHAR2(60), "CONTACT_PERSON" VARCHAR2(60), "STATUS" CHAR(1), "CREATED_BY" VARCHAR2(10), "CREATED_DATE" DATE, "MODIFIED_BY" VARCHAR2(10), "MODIFIED_DATE" DATE, "MOBILE" VARCHAR2(50))
    REM INSERTING into TBL_ACCOMMODATION
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (147,'Testt','Auckalnd','Henderson','565756776','[email protected]','Jasmine','A',null,null,'JEEJJ',to_date('23/10/12','DD/MM/RR'),null);
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (129,'Kirby Hotel','25A Aitken Street
    Wellington','Wellington','04 918 8513','[email protected]','Deahdoow Maharg','A',null,null,'LEAN',to_date('14/02/13','DD/MM/RR'),'027 356 4333');
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (167,'Avenue ee','10 Wellington Street
    Wellington','Wellington','4444444','[email protected]','James','A',null,null,'LEAN',to_date('21/02/13','DD/MM/RR'),null);
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (185,'Quadrant Hotel','10 Waterloo Quadrant,
     Auckland','Auckland','9555555','[email protected]','Quentin QQ','A',null,null,'LEAN',to_date('04/03/13','DD/MM/RR'),null);
    My select statement is
    SELECT acc.hotel_name || '(' || replace(replace(acc.address,chr(13),', '),',,',',') || ')'
    FROM TBL_ACCOMMODATION acc
      inner join ijs_seminar s ON acc.accommodation_id = s.accommodation_id 
    where s.seminar_id = :P27_SEMINAR_ID
    I have to use the function replace twice. One is to replace the Chr (13) a comma is second band a comma where there are two commas.

    I don't know much about regular expressions.
    If someone can show me a better way to handle this using the regular expression rather than a heavy means above.

    Thanks in advance
    Ann

    Hi, Ann.

    Ann586341 wrote:
    Hello everyone,

    He comes to the table that I have to work with.

    CREATE TABLE "TBL_ACCOMMODATION" ("ACCOMMODATION_ID" NUMBER, "HOTEL_NAME" VARCHAR2(100), "ADDRESS" VARCHAR2(200), "LOCATION" VARCHAR2(100), "PHONE" VARCHAR2(50), "EMAIL_ADDRESS" VARCHAR2(60), "CONTACT_PERSON" VARCHAR2(60), "STATUS" CHAR(1), "CREATED_BY" VARCHAR2(10), "CREATED_DATE" DATE, "MODIFIED_BY" VARCHAR2(10), "MODIFIED_DATE" DATE, "MOBILE" VARCHAR2(50))
    REM INSERTING into TBL_ACCOMMODATION
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (147,'Testt','Auckalnd','Henderson','565756776','[email protected]','Jasmine','A',null,null,'JEEJJ',to_date('23/10/12','DD/MM/RR'),null);
    ...
    

    Thanks for posting the sample data. You post the results, but the validation of the existing query which I suppose, produced good results. I can't run this query, because it requires the ijs_seminar table and a connection variable that also has no post, but I can just comment on the join and the WHERE clause.

    Is this really the best set of sample data for this question? This problem involves Chr (13) and repeated commas, but I don't see any s CHR (13) or repeated commas in the sample data. In addition, it seems that there are a lot of columns that play no role in this issue and just to make things difficult to read.

    My select statement is

    SELECT acc.hotel_name || '(' || replace(replace(acc.address,chr(13),', '),',,',',') || ')'
    FROM TBL_ACCOMMODATION acc
    inner join ijs_seminar s ON acc.accommodation_id = s.accommodation_id
    where s.seminar_id = :P27_SEMINAR_ID
    

    I have to use the function replace twice. We need to replace the Chr (13) by a comma,.

    As posted, inside REPLACE replaces Chr (13) with a comma and a space which could be important if you then pick up consecutive commas.

    second is the band a comma where there are two commas.

    I don't know much about regular expressions.
    If someone can show me a better way to handle this using the regular expression rather than a heavy means above.

    Assuming you want to replace Chr (13) with just a comma, then an equivalent would be:

    SELECT    acc.hotel_name || '('
                      || REGEXP_REPLACE ( acc.address
                                          , '[,' || CHR (13) || ']{1,2}'
                                , ','
                                )
                    || ')'            AS h
    FROM        tbl_accommodation acc
    INNER JOIN  ijs_seminar       s   ON   acc.accommodation_id = s.accommodation_id
    WHERE s.seminar_id = :P27_SEMINAR_ID
    ;
    

    In the argument to REGEXP_REPLACE 2nd

    [xy]{1,2}
    

    medium 1 to 2 characters of set of x and y. This could be
    x or
    there or it could be 2 characters
    XY or the other way
    YX or it could be the same characters 2
    XX or
    YY

    REGEXP_REPLACE is slower that REPLACE. Even if your original expression is longer, it may be more effective. (Performance may be not a problem in this case.)

  • help with a simple script

    We do a manual Dr, and after disabling the replication process and presents the LUN DR ESX server and run a powershell script to save virtual machines, we want to turn on all with the script below.

    It works, but I get 'this VM was copied or moved to issue a' for each I answer "moved" to. Any ideas on how to remove or to answer this question in an automated way?

    $sourceVI = Read-Host "vCenter name.
    $creds = get-credential
    to connect-viserver-Server $sourceVI - Credential $creds
    Import-Csv g:\dr\epicdrstartserverlist.csv | Foreach {Get - VM $_.} Name | {Start-vm-confirm: $false}
    Disconnect-VIServer $sourceVI - confirm: $False
    (the CSV file is just a list of the names of virtual machine I want to turn on).

    You can check the presence of an issue with the cmdlet Get-VMQuestion het and reply with the Set-VMQuestion cmdlet.

Maybe you are looking for