Android中把图片、视频保存到相册中

    /**
         * 获取fileName
         *
         * 视频+图片下载
         */
//        String videoUrl = "http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4";
        String videoUrl = "http://cdn.llsapp.com/crm_test_1449051526097.jpg";
        int i = videoUrl.lastIndexOf("/");
        final String fileName = videoUrl.substring(i + 1, videoUrl.length());
        final String subForder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera";

        File foder = new File(subForder);
        if (!foder.exists()) {
            foder.mkdirs();
        }
       
        final File myCaptureFile = new File(subForder, fileName);
        if (!myCaptureFile.exists()) {
            try {
                myCaptureFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        final DownloadUtil downloadUtil = new DownloadUtil(4, subForder, fileName, videoUrl, this);
        downloadUtil.setOnDownloadListener(new DownloadUtil.OnDownloadListener() {
            @Override
            public void Start(int fileSize) {
                Log.i("TAG---fileSize", fileSize + "");
                max = fileSize;//文件总长度
                progressBar.setMax(fileSize);
            }

            @Override
            public void Progress(int downloadedSize) {
                Log.i("TAG---downloadedSize", downloadedSize + "");
                progressBar.setProgress(downloadedSize);
                tv_progress.setText((int) downloadedSize * 100 / max + "%");
            }

            @Override
            public void End() {
                Log.i("TAG---end", "End");
                // 下载后将图片or视频保存到相册中   
                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                intent.setData(Uri.fromFile(myCaptureFile ));
                sendBroadcast(intent);//发送一个广播
            }
        });


 

你可能感兴趣的:(Android中把图片、视频保存到相册中)