我正在从解析服务器下载音频文件。运行以下代码后的结果是,当客户端单击通知时,它将播放。但是,当客户端关闭音乐播放器并将其备份打开时,它不再列出。我的问题是,该文件在哪里?我已经看到了设置外部存储位置的方法,但是我希望它与其他下载一起下载到内部存储。我该怎么做?
private class DownloadFileTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
Toast.makeText(getActivity(), getString(R.string.downloading), Toast.LENGTH_SHORT).show();
super.onPreExecute();
}
@Override
protected String doInBackground(String... urls) {
String currentSong = urls[0];
try {
downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(currentSong);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadManager.enqueue(request);
}
catch (Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
return currentSong;
}
@Override
protected void onPostExecute(String s) {
Toast.makeText(getActivity(), getString(R.string.download_complete), Toast.LENGTH_SHORT).show();
super.onPostExecute(s);
}