2015-10-08 2 views
3

я скачиваю файлы с сервера, используя DownloadManager классЗагрузка файлов с помощью менеджера загрузки

Вот что я делаю

public void downloadPdf(String url, String sem, String title, String branch) { 
    Uri Download_Uri = Uri.parse(url); 
    DownloadManager.Request request = new DownloadManager.Request(Download_Uri); 

    //Restrict the types of networks over which this download may proceed. 
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); 
    //Set whether this download may proceed over a roaming connection. 
    request.setAllowedOverRoaming(false); 
    //Set the title of this download, to be displayed in notifications (if enabled). 
    request.setTitle("Downloading"); 
    //Set a description of this download, to be displayed in notifications (if enabled) 
    request.setDescription("Downloading File"); 
    //Set the local destination for the downloaded file to a path within the application's external files directory 
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title + "_" + branch + "_" + sem + "Year" + System.currentTimeMillis() + ".pdf"); 

    //Enqueue a new download and same the referenceId 
    downloadReference = downloadManager.enqueue(request); 
} 

вещь, когда загрузка будет завершена, если затем пользователь нажимает на уведомления он должен открыть, что файл, что я должен делать в этом коде

BroadcastReceiver onNotificationClick = new BroadcastReceiver() { 
    public void onReceive(Context ctxt, Intent intent) { 

    } 
}; 

Пожалуйста, помогите

+0

Это может помочь http://www.gadgetsaint.com/android/download-manager/ – ASP

ответ

3

И наконец, исправлено это двумя строками

request.allowScanningByMediaScanner(); 
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);