30 Aralık 2015 Çarşamba

DownloadManager Sınıfı

enqueue metodu
Bir DownloadManager.Request nesnesi yaratarak indirme işlemini başlatırız. İşlemin sonucunu BroadcastReceiver ile alırız. Şöyle kullanırız.
String url = ...; File file =...;

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(Uri.parse(url));
req.setDestinationUri(Uri.fromFile(file));
req.setTitle("Some title");

BroadcastReceiver receiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    unregisterReceiver(this);
    
    }
  };
registerReceiver(receiver, new IntentFilter(
                DownloadManager.ACTION_DOWNLOAD_COMPLETE));
dm.enqueue(req);
Toast.makeText(this, "Download started", Toast.LENGTH_SHORT).show();