Thursday, February 7, 2013

Post data in android


try {

URL url = new URL(urls);
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File SDCardRoot = Environment.getExternalStorageDirectory();
File file = new File(SDCardRoot, dest);
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
Progress = "Starting image download...";
publishProgress("");

byte[] buffer = new byte[1024 * 1024];
int bufferLength = 0;
while ((bufferLength = inputStream.read(buffer)) > 0) {
fileOutput.write(buffer, 0, bufferLength);
int downloadedSize = bufferLength;

float per = ((float) downloadedSize / totalSize) * 100;

Progress = "Downloading image " + (int) per + "% complete";
publishProgress("");
}

fileOutput.close();
return setImage(dest);

} catch (final MalformedURLException e) {
}
String Proresss=null;

No comments:

Post a Comment