2016-08-23 1 views
0

ich herunterladen Datei mit diesem Code:Finden Sie heraus, Datei-Download in android

manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); String url = json_string_4_all[0]; 
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); 
id = manager.enqueue(request); 
request.setDescription("درصد دانلود "); 
request.setTitle("دانلود کتاب " + json_string_1_all[0]); 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
} 

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, json_string_1_all[0] + ".pdf");manager.enqueue(request); 

Jetzt möchte ich etwas tun, nachdem es (fertig) heruntergeladen werden.

Wie kann ich das tun?

Antwort

0

Sie könnten einen Empfänger für die ACTION_DOWNLOAD_COMPLETE Sendung erstellen:

private final BroadcastReceiver downloadReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     // download complete, do whatever you would like here 

     // optionally, check the ID of the completed download 
     long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); 
     if(id == yourId) { 
      // do your stuff 
     } 
    } 
}; 

und registrieren Sie es:

registerReceiver(downloadReceiver, 
    new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 

Vergessen Sie nicht, bei Bedarf (in onPause() zum Beispiel) deregistrieren:

unregisterReceiver(downloadReceiver); 
Verwandte Themen