简体   繁体   English

下载的文件在用户媒体应用中不可见?

[英]downloaded files not visible in user media apps?

i need to make downloaded files such as mp3 picture etc, to be visible in Media apps like album or media player 我需要制作下载的文件,如mp3图片等,以便在专辑或媒体播放器等媒体应用中可见

is it of file chmod or is not readable ? 它是文件chmod还是不可读? every thing is ok in this class but its show downloaded files inside download folder only 这个类中的每个东西都可以,但它只显示下载文件夹中的文件

this is my class 这是我的班级

public class Download extends AsyncTask<String, Void, String> {
        ProgressDialog mProgressDialog;

        Context context;
        String file_url,file_name;

        public Download(Context context,String url , String file_name) {
        this.context = context;

        this.file_url  = url;
        this.file_name = file_name;

        }

        protected void onPreExecute() {
        mProgressDialog = ProgressDialog.show(context, "",
        "Please wait, Download …");
        }

        protected String doInBackground(String... params) {



        // //////////////////////
        try {

        URL url = new URL(file_url);
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();
        String[] path = url.getPath().split("/");
        String mp3 = path[path.length - 1];
        int lengthOfFile = c.getContentLength();

        String PATH = Environment.getExternalStorageDirectory()+ "/downloads/" ;

        File file = new File(PATH);
        file.mkdirs();

        String fileName = file_name;

        File outputFile = new File(file , fileName);
        FileOutputStream fos = new FileOutputStream(outputFile);

        InputStream is = c.getInputStream();

        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = is.read(buffer)) != -1) {

        fos.write(buffer, 0, len1);
        }
        fos.close();
        is.close();

        } catch (IOException e) {
        e.printStackTrace();
        }



        return "done";
        }

        protected void onPostExecute(String result) {
        if (result.equals("done")) {
        mProgressDialog.dismiss();

        }
}

}

any idea ?? 任何想法 ??

You need to call the MediaScannerConnection and tell it to scan your file. 您需要调用MediaScannerConnection并告诉它扫描您的文件。 Documentation here . 文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM