我使用DownloadManager下载文件并从DownloadManager.COLUMN_LOCAL_URI获取其名称。下载相同的文件超过11次。 11次开始奇怪的名字。例如:DownloadManager名称,重新下载的文件
的text.txt
文本1.txt的
文本2.txt
文本3.txt
文本4.txt
文本-5.txt
text-6.txt
文本7.txt
文本8.txt
文本9.txt
文本10.txt
文本26.txt
文本的14.txt
可能是什么问题?
预先感谢您
编辑:
把我的代码
public static long downloadFile(Context ctx, String url, String title, String description, String filename, String mimetype, BroadcastReceiver onDownloadComplete) {
DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
long res = dm.enqueue(new DownloadManager.Request(Uri.parse(url)).setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI).setAllowedOverRoaming(false).setTitle(title).setMimeType(mimetype).setDescription(description).setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename));
ctx.registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Toster.showGreenToast(ctx, ctx.getString(R.string.download_started, filename));
return res;
}
public static String getDownloadCompletedFileName(Context ctx, Intent intent) {
String res = "";
try {
Bundle extras = intent.getExtras();
DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID));
Cursor c = dm.query(q);
if (c.moveToFirst()) {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL) {
// process download
res = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
// get other required data by changing the constant passed to getColumnIndex
}
}
c.close();
} catch (Exception e) {}
return res;
}
你还没有告诉我们你是如何生成文件名的。 –