Advertisement
Guest User

code

a guest
Apr 3rd, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. private void empiezaDescarga(String url) {
  2.  
  3.  
  4. descarga=new DownloadFileAsync().execute(url);
  5. }
  6.  
  7. class DownloadFileAsync extends AsyncTask<String, String, String> {
  8. String sTexto;
  9.  
  10. @Override
  11. protected void onCancelled() {
  12. super.onCancelled();
  13. File file=new File(sRutaFichero);
  14. if (file.exists())
  15. file.delete();
  16.  
  17.  
  18. }
  19.  
  20. @Override
  21. protected void onPreExecute() {
  22. super.onPreExecute();
  23. mProgressDialog = new ProgressDialog(contexto);
  24. mProgressDialog.setMessage(contexto.getString(R.string.DescargaFichero));
  25. mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  26. mProgressDialog.setCancelable(true); //establecemos que es cancelable.
  27. mProgressDialog.setOnCancelListener(new OnCancelListener(){
  28.  
  29. @Override
  30. public void onCancel(DialogInterface dialog)
  31. {
  32. descarga.cancel(true);
  33.  
  34. }
  35. });
  36. mProgressDialog.show();
  37. }
  38.  
  39. @Override
  40. protected String doInBackground(String... aurl) {
  41. int count;
  42.  
  43. try {
  44.  
  45. if(this.isCancelled()){ return null; }
  46.  
  47. URL url = new URL(aurl[0]);
  48. URLConnection conexion = url.openConnection();
  49. conexion.setConnectTimeout(TIME_OUT);
  50. conexion.connect();
  51.  
  52.  
  53. if(this.isCancelled()){ return null; }
  54.  
  55. ///// some code
  56. return null;
  57.  
  58. }
  59.  
  60. protected void onProgressUpdate(String... progress) {
  61.  
  62. mProgressDialog.setProgress(Integer.parseInt(progress[0]));
  63. }
  64.  
  65. @Override
  66. protected void onPostExecute(String unused) {
  67. mProgressDialog.dismiss();
  68.  
  69. // Some code
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement