簡體   English   中英

下載的文件在用戶媒體應用中不可見?

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

我需要制作下載的文件,如mp3圖片等,以便在專輯或媒體播放器等媒體應用中可見

它是文件chmod還是不可讀? 這個類中的每個東西都可以,但它只顯示下載文件夾中的文件

這是我的班級

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();

        }
}

}

任何想法 ??

您需要調用MediaScannerConnection並告訴它掃描您的文件。 文檔在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM