×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    How to open web page in J2Me Midlet?

    Hello, help me please. How to open web page in J2Me Midlet? I would like as here - http://www.java2s.com/Tutorial/Java/...Connection.htm but instead of pictures, opened internet page, I searched in Google, but found nothing. Help me please. Thanks =)

  2. #2
    Regular Contributor
    Join Date
    Oct 2007
    Location
    Pune
    Posts
    189

    Re: How to open web page in J2Me Midlet?

    Regards,
    Dinanath


    It's a matter of attitude.

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to open web page in J2Me Midlet?

    Quote Originally Posted by manageitems View Post
    Hello, help me please. How to open web page in J2Me Midlet? I would like as here - http://www.java2s.com/Tutorial/Java/...Connection.htm but instead of pictures, opened internet page, I searched in Google, but found nothing. Help me please. Thanks =)
    Hello manageitems,

    Welcome to the Forum Nokia Developer Baords!!!!!
    Yeah, you can give the URL that is required by you or so, and use the platformRequest(String URL) method. This will open the devices default browser.
    http://developers.sun.com/mobility/m...est/index.html
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    Re: How to open web page in J2Me Midlet?

    Thanks, but I would like to web page is opening in the MIDlet, but not in phone's internet browser. I want the J2ME function , only to open the web page in application phone. Help me please, where i can find An example MIDlet to open a page using an HttpConnection. I use the Java (TM) ME Platform SDK 3.0 . Thanks

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to open web page in J2Me Midlet?

    Hello,
    I will appreciate if you could explain the same in much details,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    Re: How to open web page in J2Me Midlet?

    I'am looking for a script to open web page in mobile phone application . Thanks =)

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to open web page in J2Me Midlet?

    Downloading data from a web server is easy enough - take a look at the example code in the Java Docs for the HttpConnection class. Displaying it, however, is another matter. There is no HTML renderer, so if you want to receive HTML and display it, you will need to write code to do this.

    Graham.

  8. #8
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    Re: How to open web page in J2Me Midlet?

    can you please advise me , some examples of code to receive and display HTML in mobile phone application

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to open web page in J2Me Midlet?

    What you are asking for is the complete code for a web browser! I'm afraid that goes slightly beyond the realms of "sample code".

    Graham.

  10. #10
    Regular Contributor
    Join Date
    Oct 2007
    Location
    Pune
    Posts
    189

    Re: How to open web page in J2Me Midlet?

    Hello,

    You can check this.

    The sample application given on this atleast working on Nokia N95. I tried it.
    Regards,
    Dinanath


    It's a matter of attitude.

  11. #11
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Re: How to open web page in J2Me Midlet?

    Yes you can open a web page from a Midlet with a slight effort.
    Open the http connection and get the bytes normally and make it a String like:

    conn = (HttpConnection)Connector.open(
    "http:/yourwebsite/TestImage.html",
    Connector.READ_WRITE);
    if (conn.getResponseCode() != HttpConnection.HTTP_NOT_FOUND){
    is = conn.openInputStream();
    final int MAX_LENGTH = 128;
    byte[] buf = new byte[MAX_LENGTH];
    int total = 0;
    while (total < MAX_LENGTH) {
    int count = is.read(buf, total, MAX_LENGTH - total);
    if (count < 0) {
    break;
    }
    total += count;
    }
    is.close();
    String reply = new String(buf, 0, total);
    conn.close();

    Then extract the url of the image from it like:
    int begin= reply.indexOf("IMG SRC=");
    int end= reply.indexOf(".png");
    String url = reply.substring(begin + 9, end + 4);
    After this get the image and append it with the form similar to that given at:
    http://www.java2s.com/Tutorial/Java/...Connection.htm
    Last edited by NiteshGarg; 2010-04-10 at 14:20.

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How to open web page in J2Me Midlet?

    Or Simply do a platform request to open the webpage in the phone browser from your J2me app.
    Midlet.platforRequest("URL");

    thanks,
    ~Amitabh

  13. #13
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Re: How to open web page in J2Me Midlet?

    Yeah sure patformRequest method can be used but that uses your default phone browser and minimizes/exits your midlet.

    ~~
    Nitesh
    nitesh_hulk[at]yahoo[com]

  14. #14
    Registered User
    Join Date
    Mar 2010
    Posts
    10

    Wink Re: How to open web page in J2Me Midlet?

    Dear,
    Can I create application enter the websites and complete insert parameter automatically, if the code read specific data for example I will send data if files depend obex protocol and the application read the data and just if there specific numbers i.e above 1000. will enter to website and complete the transaction


    help help pleaseeeeeee

  15. #15
    letdocoding
    Guest

    Exclamation Re: How to open web page in J2Me Midlet?

    Hi
    I am also trying to create a similar MIDlet in which i enter the URL n click on submit n the data is sent to a server(pc) via bluetooth n the server retrieves the URL n fetches the corresponding page n sends it back to the client via bluetooth. I found the following codes online n tried to implement them. But, there should be a BrowserScreen class along with this. Since i'm new to MIDlet programming i'm not able to understand how to solve this. What should be in this BrowserScreen?

    This is the MIDlet, TextFieldCapture.

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java .lang.*;
    public class TextFieldCapture extends MIDlet
    implements CommandListener
    {
    private Display display;
    public Form form;
    private Command submit;
    private Command exit;
    private TextField textfield;
    private ClientServer m_BlueObj;
    private boolean m_bIsServer=false;
    private BrowserScreen bsr;
    public String str;
    public TextFieldCapture()
    {
    display = Display.getDisplay(this);
    submit = new Command("Submit", Command.SCREEN, 1);
    exit = new Command("Exit", Command.EXIT, 1);
    textfield = new TextField("Enter URL:", "", 30, TextField.ANY);
    form = new Form("Web Page Viewer");
    form.addCommand(exit);
    form.addCommand(submit);
    form.append(textfield);
    form.setCommandListener(this);
    textfield.setString("http://www.");
    }
    public BrowserScreen browserCanvas () {
    return bsr;
    }
    public void DispNow(BrowserScreen Browser)
    {
    this.bsr=Browser;
    display.setCurrent(bsr);
    }
    public void startApp()
    {
    display.setCurrent(form);
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean unconditional)
    {
    m_BlueObj.CloseAll();
    }
    public void openBsr(String str)
    {
    bsr=new BrowserScreen(this);
    StringItem si = new StringItem("Browser initiated", null);
    si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER);
    form.append(si);
    Display.getDisplay(this).setCurrent(form);

    //this.DispNow(bsr);

    bsr.getURL(str);

    System.out.println("Browser given data");
    si = new StringItem("Browser given data", null);
    si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER);
    form.append(si);
    Display.getDisplay(this).setCurrent(form);

    display.setCurrent(bsr);
    }

    public void commandAction(Command command, Displayable displayable)
    {
    if (command == submit)
    {

    String s=textfield.getString();
    textfield.setString(s);
    form.removeCommand(submit);
    m_BlueObj=new ClientServer(this,s);
    }
    else if (command == exit)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    }
    }
    This is the ClintServer code.

    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.bluetooth.BluetoothStateException;
    import javax.bluetooth.DeviceClass;
    import javax.bluetooth.DiscoveryAgent;
    import javax.bluetooth.DiscoveryListener;
    import javax.bluetooth.LocalDevice;
    import javax.bluetooth.RemoteDevice;
    import javax.bluetooth.ServiceRecord;
    import javax.bluetooth.UUID;
    import javax.microedition.io.Connector;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.io.StreamConnectionNotifier;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    public class ClientServer implements DiscoveryListener{

    /** Creates a new instance of ClientServer */
    UUID RFCOMM_UUID = new UUID(0x0003);
    private String m_ServerUrl = "btspp://localhost:" + RFCOMM_UUID + ";name=rfcommtest;authorize=true";
    private StreamConnection m_StrmConn = null;
    private LocalDevice m_LclDevice = null;
    private InputStream m_Input=null;
    private OutputStream m_Output=null;
    private StreamConnectionNotifier m_StrmNotf=null;
    public boolean m_bIsServer=false,m_bServerFound=false,m_bInitServer=false,m_bInitClient=false;
    private static String m_strUrl;
    private final String SEVER_RESPONSE= "RUN_THE_GAME",CLIENT_RESPONSE="CLIENT_IS_READY";
    private DiscoveryAgent m_DscrAgent=null;
    private String str=null;
    private Form form;
    private TextFieldCapture tf;

    public ClientServer(TextFieldCapture tf,String str)
    {
    this.tf=tf;
    this.form=tf.form;
    this.str=str;
    InitClient();

    }



    private void InitClient()
    {
    SearchAvailDevices();

    }

    public void SearchAvailDevices()
    {
    try
    {
    //First get the local device and obtain the discovery agent.
    m_LclDevice = LocalDevice.getLocalDevice();

    m_DscrAgent= m_LclDevice.getDiscoveryAgent();

    m_DscrAgent.startInquiry(DiscoveryAgent.GIAC,this);
    }
    catch (BluetoothStateException ex)
    {
    System.out.println("Problem in searching the bluetooth devices");
    ex.printStackTrace();
    }

    }


    public void SendMessages(String v_strData)
    {
    try
    {
    m_Output.write(v_strData.length());
    m_Output.write(v_strData.getBytes());
    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    }

    }


    @Override
    public void inquiryCompleted(int discType)
    {
    System.out.println("InquiryCompleted");

    }

    //called when service search gets complete
    @Override
    public void serviceSearchCompleted(int transID, int respCode)
    {
    if(m_bServerFound)
    {
    try
    { //lets the communication start by setting the url and send client reponse
    m_StrmConn = (StreamConnection) Connector.open(m_strUrl);

    m_Output = m_StrmConn.openOutputStream();
    m_Input = m_StrmConn.openInputStream();

    //m_Output.write(CLIENT_RESPONSE.length());
    //m_Output.write(CLIENT_RESPONSE.getBytes());
    //SendMessages(str);
    try
    {
    m_Output.write(str.length());
    m_Output.write(str.getBytes());
    m_Output.close();
    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    }
    String st=null;
    try{
    byte[] b=new byte[64];
    int p=m_Input.read(b);

    System.out.print("data read " +p);
    st=new String(b);

    StringItem si = new StringItem("hello "+st, null);
    si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER);
    form.append(si);
    Display.getDisplay(tf).setCurrent(form);
    m_Input.close();
    }catch(IOException ex){ex.printStackTrace();
    StringItem si = new StringItem("Error......", null);
    si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER);
    form.append(si);
    Display.getDisplay(tf).setCurrent(form);
    }
    tf.openBsr(st);
    System.out.println("serviceSearchCompleted");
    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    }

    }
    }

    void CloseAll()
    {
    try
    {
    if( m_Output!=null)
    m_Output.close();


    if( m_Input!=null)
    m_Input.close();
    }
    catch (IOException ex)
    {
    ex.printStackTrace();
    }

    }

    //called when service found during service search
    /**
    *
    * @param transID
    * @param records
    */

    @Override
    public void servicesDiscovered(int transID, ServiceRecord[] records)
    {

    for (int i = 0; i < records.length; i++)
    {
    m_strUrl = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);

    System.out.println(m_strUrl);
    if(m_strUrl.startsWith("btspp://111111111111:")) //we have found our service protocol
    {
    m_bServerFound = true;
    m_bInitClient=true;
    break;
    }

    }

    }


    /**
    *
    * @param btDevice
    * @param cod
    */

    //Called when device is found during inquiry
    @Override
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
    {

    try
    {
    // Get Device Info
    System.out.println("Device Discovered");
    System.out.println("Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
    System.out.println("Bluetooth Address: " + btDevice.getBluetoothAddress());
    System.out.println("Bluetooth Friendly Name: " + btDevice.getFriendlyName(true));

    // Search for Services
    UUID uuidSet[] = new UUID[1];
    uuidSet[0] = RFCOMM_UUID;
    int searchID = m_DscrAgent.searchServices(null,uuidSet,btDevice,this);
    }
    catch (Exception e)
    {
    System.out.println("Device Discovered Error: " + e);
    }
    }
    }
    Last edited by letdocoding; 2013-10-11 at 19:21.

Similar Threads

  1. Open C FAQ
    By Nokia Ron in forum Open C/C++
    Replies: 4
    Last Post: 2010-10-01, 09:02
  2. How to browse web page through in J2ME
    By sumeshchakra in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2010-01-11, 11:44
  3. How to make a WORKING J2ME Web Services client?
    By ebigogno in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2009-03-19, 13:24
  4. 技术文档:MIDP 2.0安全机制 与 MIDlet 数字签名
    By wotrust in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 0
    Last Post: 2006-12-30, 08:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×