how to save a downloaded file into internal storage in android?

爱⌒轻易说出口 提交于 2020-02-23 07:46:10

问题


i have used the below code to download a video from server in android studio and it works correctly , but when i search the video in my device i cant find it anywhere ... where does it save and how can i change destination directory on "internal storage"?

private DownloadManager downloadManager;

btn_download_video.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
            Uri uri = Uri.parse(urlVideo);
            DownloadManager.Request request = new DownloadManager.Request(uri);
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setDestinationInExternalFilesDir(Video_detail_Activity.this, Environment.DIRECTORY_DOWNLOADS, videoName);
            Long reference = downloadManager.enqueue(request);

        }
 });

i used below permissions in my project too:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

回答1:


thanks for helping ... as pskink said i changed

request.setDestinationInExternalFilesDir(Video_detail_Activity.this, Environment.DIRECTORY_DOWNLOADS, videoName);

to

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS.toString(), videoName+".mp4");

and now i can see downloaded file in "Download" folder.



来源:https://stackoverflow.com/questions/44867730/how-to-save-a-downloaded-file-into-internal-storage-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!