java如何在下载接收器中访问本地文件名?
我正在尝试获取下载文件的文件路径,我提供了接收器,该接收器可以工作,但如何获取文件名/路径
内部接收
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
DownloadManager.Query q = new DownloadManager.Query();
Cursor c = this.query(q); // how to get access to this since there is no instance of DownloadManager
try {
String filePath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
Log.i("DOWNLOAD LISTENER", filePath);
} catch(Exception e) {
} finally {
c.close();
}
}
Cannot resolve method query(...)
# 1 楼答案
您可以通过
Context
的getSystemService()
方法获得DownloadManager
实例像这样的方法应该有用: