Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
servertest;
import
import
import
import
import
import
java.io.BufferedInputStream;
java.io.FileOutputStream;
java.io.InputStream;
java.io.OutputStream;
java.net.URL;
java.net.URLConnection;
import
import
import
import
import
import
import
import
import
import
import
android.app.Activity;
android.app.Dialog;
android.app.ProgressDialog;
android.graphics.drawable.Drawable;
android.os.AsyncTask;
android.os.Bundle;
android.os.Environment;
android.util.Log;
android.view.View;
android.widget.Button;
android.widget.ImageView;
});
}
/**
* Showing Dialog
* */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading Specials. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}
/**
* Background Async Task to download file
* */
class DownloadFileFromURL extends AsyncTask<String, String, String> {
/**
* Before starting background thread
* Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
* */
@Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(), 81
92);
// Output stream to write file
OutputStream output = new FileOutputStream("/sdcard/GroceryRun+/
beverages1.png");
OutputStream output2 = new FileOutputStream("/sdcard/GroceryRun+
/beverages2.png");