Download a file programmatically on Android

后端 未结 5 590
猫巷女王i
猫巷女王i 2020-11-28 04:43

I am downloading files from web server programmatically. After download is completed, I checked the file. The size ,extension and all other parameters are correct but when I

5条回答
  •  攒了一身酷
    2020-11-28 05:15

    Permission

    
    
    
    
    
    
    
    

    Download Fuction Code

     public void downloadFile() {
            String DownloadUrl = audio1;
            DownloadManager.Request request1 = new DownloadManager.Request(Uri.parse(DownloadUrl));
            request1.setDescription("Sample Music File");   //appears the same in Notification bar while downloading
            request1.setTitle("File1.mp3");
            request1.setVisibleInDownloadsUi(false);
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                request1.allowScanningByMediaScanner();
                request1.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
            }
            request1.setDestinationInExternalFilesDir(getApplicationContext(), "/File", "Question1.mp3");
    
            DownloadManager manager1 = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            Objects.requireNonNull(manager1).enqueue(request1);
            if (DownloadManager.STATUS_SUCCESSFUL == 8) {
            DownloadSuccess(); 
            }
        }
    

提交回复
热议问题