将电影文件保存在特定文件夹中 - 机器人 -

时间:2017-04-16 05:57:12

标签: java android download android-sdcard

我有一个从YouTube下载视频的Android代码,它工作正常,但它将视频文件保存在应用程序文件夹中,我无法在“视频”公用文件夹中找到该视频

public void onNext(String downloadUrl) {
    dismissWaitDialog();

    String fileName = fmtStreamMap.title + "." + fmtStreamMap.extension;
    /*Added By Morad*/
    if (fmtStreamMap.extension.contains("mp3")) {
        Uri uri = Uri.parse(downloadUrl);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setDestinationInExternalFilesDir(MainActivity.this,Environment.DIRECTORY_MUSIC, fileName);
        downloadManager.enqueue(request);
    } else {
        Uri uri = Uri.parse(downloadUrl);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setDestinationInExternalFilesDir(MainActivity.this,DIRECTORY_MOVIES, fileName);
        //request.setDestinationInExternalPublicDir(DIRECTORY_MOVIES, fileName);
        downloadManager.enqueue(request);
    }
}

我使用了request.setDestinationInExternalPublicDir(DIRECTORY_MOVIES, fileName);,但它没有用。

1 个答案:

答案 0 :(得分:0)

 btn.setTitle("mybtn", for: .normal)
 btn.setTitleColor(UIColor.blue, for: .normal)
 btn.backgroundColor = UIColor.gray

 btn.translatesAutoresizingMaskIntoConstraints = false
 self.view.addSubview(btn)


let left = NSLayoutConstraint(item: btn, attribute: .leftMargin, relatedBy: .equal, toItem: view, attribute: .leftMargin, multiplier: 1.0, constant: 0)

let right = NSLayoutConstraint(item: btn, attribute: .rightMargin, relatedBy: .equal, toItem: view, attribute: .rightMargin, multiplier: 1.0, constant: 0)

let top = NSLayoutConstraint(item: btn, attribute: .top, relatedBy: .equal, toItem: topLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0)

// here you have to call activate constraints everything will work     
NSLayoutConstraint.activate([left, right, top])