每当我尝试通过下面的代码下载任何文件时
dm = (DownloadManager) context.getSystemService(context.DOWNLOAD_SERVICE);
request = new Request(
Uri.parse(finalurl));
enqueue = dm.enqueue(request);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
Query query = new Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {
Toast.makeText(context, "download finished", Toast.LENGTH_LONG).show();
}
}
}
}
};
context.registerReceiver(receiver, new IntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));
下载的文件显示在Download Manager Application中,可以随时从那里播放,但是不会将下载的文件存储在Downloads文件夹中。
如果我用
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "filename.extention"));
我得到相同的结果。
我的问题是-我的下载要去哪里,如何将它们带到downloads文件夹?
要查看下载的文件,您必须在手机中安装“文件管理器”应用程序。查看下载文件的步骤:
路径是:storage / sdcard / Android / data /“您的包”
使用以下方法将文件保存在下载文件夹中
.setDestinationInExternalFilesDir(this, dir, "abc.png");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句