Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

android - I write a file to Environment.DIRECTORY_DOWNLOADS, why can't I see it via the Downloads App?

I write (write, not download, to be precise it is the dump of a SQLite db of my App) a file on the Environment.DIRECTORY_DOWNLOADS directory.

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, "db.csv");

If I browse the phone with a file browser, I can see correctly the file in the

  /storage/emulated/0/Download

Directory, together with the other downloads.

But if I open the Downloads App it does not show...

What do I need to do to have the file shown in the Downloads App as well?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In case anyone wonder how to do this, I found the answer here

To allow the System to display you file in the "Downloads" App, you need to explicitly notify the DownloadManager that a download as been completed by using the method addCompletedDownload()

By using it, the system will allow your Download App to display the file you have created yourself.

Hope it will help.

UPD: This method was deprecated in API level 29.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...