android - where does WebView download its files to? - android

I am implementing a simple download system in the embedded webview, by intercepting the click using shouldOverrideUrlLoading and then call:
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url));
startActivity(intent);
This opens the native browser, shows an indicator that the file is being downloaded, and once it's completed I can pull down the notification list to view the file. I have several questions though:
Where does WebView download its files to?
Is this a temporary cache or is it persistent? Can I access it offline?
How can my WebView gets informed when the download completes?
Ultimately what I'm trying to achieve is that, once the file is downloaded, the next time the user clicks to the link, it will open up the local downloaded file, instead of trying to download it again.

Looking at the emulator through the DDMS perspective in Eclipse it looks like the files are downloaded to either yourAppsNamespace/cache/webviewCache or actually into the yourAppsNamespace/databases/ . So the file should be a permanent download. As to knowing when the download is complete i am not sure

Related

How to launch my downloader app when chrome encounters a download link on android?

I am making a download manager app. I need an activity (assume MainActivity) to popup when user is trying to download a file from his default browser (say chrome).
Basically I need to grab a download from chrome.
How to do this?

Android Webview with link new tab

Let's say I have an Android app that uses a webview. Inside that webview I have a link to download a PDF file like so:
<a href="LinkToDownloadPDF" target="_blank".../>
In a browser (Say Chrome for example), this will either download the file or opens it in a new tab.
My question is, what will happen once the webview is charged in the Android app? Will it download the file or open the web browser?
Nothing will happen when you download from webview without setting the download listener.
If you want to implement the feature of downloading something inside WebView, have a look at this question: Download File inside WebView

Make app generated content show in stock android Downloads app

We are working on an android app that generates PDFs based on app contents on users' request. We are providing an option to launch an email agent and attach the generate PDF, but we also want the user be able to view the document later at any time. On android, there are no stock file explorer, so our first thought was to show on the stock Downloads app's file list. We've tried the following two methods but without luck.
We firstly tried to save the PDF to the default download folder (given by calling Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)) and invoke media scanner, but the file doesn't show up in the Downloads app's list. It's shown in Adobe Acrobat's local document list though.
After some research, it seems that the Downloads app would only show files that downloaded though DownloadManager, so we tried to generate the PDF in a temporary directory and call DownloadManager to download it, but, somehow expected, it complains that we can only download via HTTP(S), so this approach isn't working as well.
Is there any other solution?
well if you have to provide access to the document without any file explorer app, i think your approach is correct it to allow to store it in the Download lists. To achive this you can use Nanohttpd in your application to host your pdf document and then invoke the DownloadManager download action using HTTP(S) to your webapp (you will have to create a small webapp to handle the download request) hosted on localhost server.

Android: download file programatically using the browser

My app has a string containing the URL to a file, typically something like a Word document or a PDF file. I want to give the user a way to download the file the same way they would if they had clicked on a link in the browser (letting the browser store it in the default location, etc).
At the moment I am doing this by launching an ACTION_VIEW intent. It works in most cases, but there are several problems with it. Often the browser window tries to display a message which for some reason immediately disappears and can't be read. Sometimes the download fails and I can't detect that. If it does succeed, all the user really sees is a small icon in the top status bar that they have to know to look for.
Is there a better way to do this? Some way to start a dedicated DOWNLOAD action instead of invoking the whole browser?
Could I download the file myself in my own code and then somehow cause it to end up in the same place as if the browser had downloaded it?
Thanks.
You can download it with your own code, and place it in the \Download folder on the SD card. Alternatively, you could use the DownloadManager available on API 9 and above.

Android browser download manager

Can I use android build-in browser download manager to download files in my application?
In case of audio files, opening remote file url using Intent.ACTION_VIEW with data type "audio/*" causes browser to start playback, but I'd like to force download of specified file.
The download manager is not part of the public SDK. You are welcome to download files from URLs via HttpURLConnection or HttpClient, both part of the Android SDK.
I am wondering exactly the same. It seems like a waste of time to write a service which handles download/resume/checking connection etc, when I just want to say downloadFile(URL myURL). Is there anything that could be re-used? Android Market also has a downloader...
http://developer.android.com/reference/android/app/DownloadManager.html
Can some one tell what is this? If download Manager isnt a part of SDK.
Seems to me like a complete download manager. I will try this soon.

Categories

Resources