Android的下载管理器获得的文件名 [英] Android DownloadManager get filename
本文介绍了Android的下载管理器获得的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,你可以下载一些文件。我用过Android 下载管理器
类下载。下载完成后,它应该显示我已下载的文件的消息。的问题是,有可能是2,3或4的下载在同一时间。我的的BroadcastReceiver
code是这样的:
In my app you can download some files. I used the Android DownloadManager
class for downloading. After the download is completed, it should show me a message that the file was downloaded. The problem is, there could be 2,3 or 4 downloads at the same time. My BroadcastReceiver
code looks like this:
receiver_complete = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE) ){
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.download_finished, "Here should be the name", Toast.LENGTH_SHORT).show();
}
}
};
我怎样才能得到最终下载的当前文件名?
How can I get the current filename of the finished download?
非常感谢你。
推荐答案
我想你想要把这样的事情在你的如果
块。替换 YOUR_DM
您的下载管理器实例。
I think you want to put something like this inside your if
block. Replace YOUR_DM
with your DownloadManager instance.
Bundle extras = intent.getExtras();
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID));
Cursor c = YOUR_DM.query(q);
if (c.moveToFirst()) {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL) {
// process download
title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
// get other required data by changing the constant passed to getColumnIndex
}
}
这篇关于Android的下载管理器获得的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文