Programming/Non programming

Friday, February 19, 2010

How to retrieve HTTP URL data programmatically on Android:

How to retrieve HTTP URL data programmatically on Android:

Here is the simple function:

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;


private String getURLRequestData ()
{
String contentData=null;

try {

URL url1 = new URL("http://www.xxxx.com/xxxx.html");
URLConnection con = url1.openConnection();

InputStream is = con.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);

ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ( (current = bis.read())!=-1 )
{
baf.append((byte)current);
}
contentData = new String(baf.toByteArray());

} catch (IOException e) {
e.printStackTrace();
}

return contentData; // you will get output code get from the URL given..
}

After getting this, you can look up, how to parse the data to have with your requirements.

Thanks you.

Cheers !

M.P.Prabakar
Senior Systems Analyst.

How to setup internet connetivity on Android Emulator?

How to set up Internet Connectivity on Android Simulator?

This is how we can setup Internet connectivity on Android Simulator if it doesn't take connection automatically.

1. Make sure there is 3G icon shown on top of the emulator screen. If no, reset the emulator until it comes.

2. Add the following line lastly in your application manifest file, which will be in your project folder path as AndroidManifest.xml.







This will do it !!!

Cheers !

M.P.Prabakar
Systems Analyst.