A J2ME application that connects and read data from HTTP protocol

This example shows you how to connect and read data from a http protocol. When you implement it and run it from your mobile device, you have to change the url from localhost to a real hosting address. (Like http://www.ftechdb.com/somefile.txt)

/*
* Midlet.java
*
* Created on March 14, 2007, 1:15 PM
*/

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;

/**
*
* @author  mahmud
* @version
*/
public class Midlet extends MIDlet {
private Display display;
private Form form;
public void startApp() {
display = Display.getDisplay(this);

form = new Form(“Http Example”);
StringBuffer buffer = null;

try{

// you could use other http://www.something.com/file.html as a example

String url = “http://localhost/shaon.txt”;

StreamConnection conn = (StreamConnection) Connector.open(url);
InputStream in = conn.openInputStream();

buffer = new StringBuffer();
int ch;

while ( (ch = in.read())!= -1){
buffer.append( (char) ch);

}
}
catch(Exception o){
o.printStackTrace();
}

form.append(new StringItem(null, buffer.toString()));
display.setCurrent(form);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
}

Advertisements
Posted in J2ME. Tags: , , . 1 Comment »

One Response to “A J2ME application that connects and read data from HTTP protocol”

  1. Fuad Says:

    Hello Mahmud,
    Can you just tell me how the content provider companies are doing their business? If you know then please tell me both from technical and business perspective. In terms of technical I mean,,, how are they connected with phone companies? are they using their own applications and server to manage the contents? or what? my email address is fuad@thevervegroup.com … you can email me… thank you


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: