Commit 26031db4f926fba5ff5908c31bfe943d6cf08a44
1 parent
d1aa769e
--no commit message
Showing
2 changed files
with
20 additions
and
0 deletions
src/com/upc/pbe/upcnews/Descarrega.java
@@ -26,6 +26,7 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | @@ -26,6 +26,7 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | ||
26 | 26 | ||
27 | public void descarregarguardar(String url, String path) throws IOException | 27 | public void descarregarguardar(String url, String path) throws IOException |
28 | { | 28 | { |
29 | + | ||
29 | // Descarrega un arxiu i el guarda | 30 | // Descarrega un arxiu i el guarda |
30 | // Creem l'arxiu | 31 | // Creem l'arxiu |
31 | File file = new File(path + url.substring(url.lastIndexOf("/")+1, url.length())); | 32 | File file = new File(path + url.substring(url.lastIndexOf("/")+1, url.length())); |
@@ -47,6 +48,9 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | @@ -47,6 +48,9 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | ||
47 | out.flush(); | 48 | out.flush(); |
48 | out.close(); | 49 | out.close(); |
49 | in.close(); | 50 | in.close(); |
51 | + | ||
52 | + | ||
53 | + | ||
50 | } | 54 | } |
51 | 55 | ||
52 | protected String doInBackground(String url) throws IOException | 56 | protected String doInBackground(String url) throws IOException |
src/com/upc/pbe/upcnews/MainActivity.java
@@ -6,10 +6,15 @@ import java.net.MalformedURLException; | @@ -6,10 +6,15 @@ import java.net.MalformedURLException; | ||
6 | import java.util.List; | 6 | import java.util.List; |
7 | 7 | ||
8 | import android.app.Activity; | 8 | import android.app.Activity; |
9 | +import android.app.DownloadManager; | ||
10 | +import android.app.DownloadManager.Request; | ||
11 | +import android.content.Context; | ||
9 | import android.content.Intent; | 12 | import android.content.Intent; |
10 | import android.content.pm.PackageInfo; | 13 | import android.content.pm.PackageInfo; |
11 | import android.content.pm.PackageManager; | 14 | import android.content.pm.PackageManager; |
15 | +import android.net.Uri; | ||
12 | import android.os.Bundle; | 16 | import android.os.Bundle; |
17 | +import android.os.Environment; | ||
13 | import android.util.Log; | 18 | import android.util.Log; |
14 | import android.view.Menu; | 19 | import android.view.Menu; |
15 | import android.view.MenuItem; | 20 | import android.view.MenuItem; |
@@ -42,6 +47,17 @@ public class MainActivity extends Activity implements OnClickListener { | @@ -42,6 +47,17 @@ public class MainActivity extends Activity implements OnClickListener { | ||
42 | if(tempFolder.mkdirs()) { | 47 | if(tempFolder.mkdirs()) { |
43 | Log.d(TAG,"Directori " + tempFolder.toString() + " creat"); | 48 | Log.d(TAG,"Directori " + tempFolder.toString() + " creat"); |
44 | } | 49 | } |
50 | + | ||
51 | + String url = "http://revistes.upc.es/~imanol/PBE/sample_ep_128k-00001.ts"; | ||
52 | + Request req = new Request(Uri.parse(url)); | ||
53 | + req.setTitle("TestTitle"); | ||
54 | + req.setDescription("TestDescription"); | ||
55 | + //req.setVisibleInDownloadsUi(false); | ||
56 | + req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "a.ts"); | ||
57 | + DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); | ||
58 | + manager.enqueue(req); | ||
59 | + | ||
60 | + | ||
45 | //Creem els botons i text | 61 | //Creem els botons i text |
46 | URLText = (TextView) findViewById(R.id.textViewUrl); | 62 | URLText = (TextView) findViewById(R.id.textViewUrl); |
47 | buttonDescarrega = (ImageButton) findViewById(R.id.button); | 63 | buttonDescarrega = (ImageButton) findViewById(R.id.button); |