Android: download file programatically using the browser - android

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.

Related

Update offline webpages without updating app

I have an app which contains html files which i am displaying using a webview. This html files are nothing but documentation the users of my app require. My question is, can I update these html files without asking the user to update the entire app? I dont want to replace these html files by hosting the documentaion online.
You will have to do one of these:
Update your app (which is what you don't want)
Host the raw .html files on a web server, and whenever the user opens the app, check if there are new files available and download them.
Simply create a website that shows the .html files and open the
website in your app (which i'm guessing is what you don't want
either)
So you're left with option 2.
To update files without requiring an app update, you will need the app to obtain the HTML content online.
One option, which you mentioned you don't want, is loading a URL into the WebView rather than local HTML files.
The other option would involve hosting the web pages somewhere and the app would download them. The only benefit of this I can see, is that if the device is offline is can use the last obtained HTML file. You could just use caching to achieve this though.
How complicated are the webpages? Using JSON is another method.

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 - where does WebView download its files to?

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

Android PDF viewer app to be invoked

I need a pointer to a (preferably free) PDF viewer app that I can invoke on a file or URL link via a startActivity on an Intent. I know that there is no real standard - I have one phone that came with OpenOffice that can read local PDF files, and one phone that has no built-in PDF reader.
What I want is the name of an application that I can suggest to my users to download from the market that is a PDF viewer that I can invoke by configuring an Intent and calling startActivity. I would make this suggestion when I intercept a URL to a pdf file, and discover that the application is not yet installed. Although ugly, this is better than the blank screen they get now because the built in browser doesn't do PDF.
I already installed Adobe's PDF viewer but it is not showing up in the package manager as being a candidate to handle PDF files.
I have used the technique suggested in SO:how-to-render-pdf-in-android to examine the candidate activities for a URL based PDF link and a local file PDF link and see that the com.android.browser.Browser is always invoked for http:// URL links; a URL of "file.pdf" causes OpenOffice to be selected on one phone and nothing on the other phone. Adobe's PDF viewer is not a candidate for either approach.
I tried the Google Docs viewer approach (as suggested in SO:android-load-pdf-pdf-viewer but that leaves a lot to be desired, especially as the PDF image I tried to load kept moving further and further down the device's screen until a user would need to scroll several screen fulls of blank screen to get to the document.
I see libraries such as android-pdf-viewer as a potential solution. But I'd prefer to link to another application rather than build in PDF support (including the fonts, etc) into my application. This then allows my application to support multiple PDF viewer applications - choosing one that the user has already installed or suggesting my favorite one if no compatible reader is present when I need it. Potentially I could see using these types of libraries to create such an application and load it to the market place, but before doing that I want to make sure that I'm not re-inventing the wheel.
I found the droid-reader application which looks promising, but this doesn't appear to be available from the market place. While I'm personally comfortable with the gymnastics of downloading files to my sdcard and installing from there, its not a viable option for the general public user that I'm targeting.
I hope the following code snippit would be helpful to you for reading pdfs. It will use the default pdf viewer that has been set on your device.
Intent intent= new Intent(Intent.ACTION_VIEW);
File f = new File("/mnt/sdcard/file.pdf");
intent.setDataAndType(Uri.fromFile(f),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

System call to open a pdf on Entourage eDGe's E-Reader

I am trying to write an app that requires different PDF files to be opened and displayed on the E-Reader side of the eDGe's dual screens while the app is running on the LCD side. I've been using Better Terminal Emulator to cruise around the eDGe's file system but can't seem to find the command that opens PDF files. Does anyone know it or is there even one?
I'm going to answer my own question in case someone runs into the same issue. Using an intent with the action set as ACTION_VIEW, the mime type set as application/pdf, and a pdf file as the data, the Library will handle the intent.

Categories

Resources