I'm in the middle of writing an Android app, and would like to give my users the ability to share the document files it creates.
What I'd ideally like to see would be files hosted on a HTTP server somewhere, so a user can simply fire up their browser on the Android phone, surf to the relevant page, and then download the file to their phone. I'd then like for my app to be able to open that downloaded file.
I'm not sure if that's possible at all, but would certainly be interested in hearing from anyone that knows anything about such things. Unfortunately I seem to be having difficulty coming up with the answers myself - like much of the rest of the Android SDK, there is a severe shortage of relevant documentation.
When the user access a file you wish to support you should be able to register with Android using IntentFilters to indicate that your application is able to handle a specific MIME-TYPE.
See the documentation here .
It's easy enough to get files from a web server.
In your includes -
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
In your code -
URL requestURL = new URL(urlStringForFileYouWantToOpen);
URLConnection connection = requestURL.openConnection();
InputStream response = connection.getInputStream();
Then do what you want with the InputStream. I'm not sure if that's close enough to your description of the user downloading a file and then accessing it from your app, but it seems more straightforward to me to let them get the file while in your app.
Incidentally, I've stumbled across a reasonable solution that is a fair bit easier than messing around with intents and so on...
The WebView widget allows you to set a DownloadListener object that gets notified whenever the WebView is directed to a file of a type it doesn't natively understand. Thus, the functionality I was after can be achieved by creating a WebView in my application and registering a DownloadListener to listen for when the user downloads one of my application's document files.
Thanks for all your help!
If you want to integrate the download from within the app then #jball's answer is what you need if your would prefer that the process is initiated via the browser then #Scott's answer is what you need.
From your description it sounds like you also want users to share documents created with the app which would require your app to be able to upload apps to the webserver. Something like WebDAV would be ideal for that, either implemented yourself using org.apache.http library or using one of the open source implementations out their.
Related
I'm not sure if this is the right place to ask this question but I've looked around and couldn't find the answer.
An app that I'm building allows the user to download files, but I want to protect the URL of the files.
Is there a way to find the URL of a file being downloaded via an app?
If there is, can I prevent it somehow?
I am using download manager to download the files. Is it any different in this aspect if I write my own async methods?
Similarly, can users see the GET requests sent by the app?
Any info or direction to pages that talk more about this is appreciated.
Thanks.
I am using download manager to download the files. Is it any different in this aspect if I write my own async methods?
If you are using DownloadManager to download files, depending on how you're using it, yes, users could get the URL quite easily, since the downloads app may show it. (this depends on how you're actually doing the download with DownloadManager, I'd need to see your code in order to tell you for sure.
If you write your own code to do the download, then yes, it will be harder for users to figure out where the file is being downloaded from.
Is there a way to find the URL of a file being downloaded via an app?
Even if you don't use DownloadManager, it is still possible, just more difficult. If users are using a firewall which logs network accesses, or something similar, your URLs will be logged and visible. Similarly, users can use a tool like Wireshark to see all networ traffic going between the device (and your app) and the server your data is coming from. On rooted devices, users can also install monitoring tools.
Similarly, can users see the GET requests sent by the app?
Yes, using the same tools (eg. wireshark), one can see exactly what URLs your app is requesting.
If there is, can I prevent it somehow?
No. If someone wants this information, they will get it, all you can do is make it harder. For starters though, I'd recommend not using DownloadManager and writing your own code instead, and using HTTPS. Additionally, you could try to ensure that your URL only works for users which have been authenticated in some way - check this question for possibilities.
Let me know if you have any other questions, and I'll try to help.
I'm developing a simple Android App where the user must fill in a very complex form, for which I believe it's much easier to use an HTML form than an Android Activity with tons of TextViews.
The data collected by the form must be sent to some remote database, and the application must be able to work offline.
I thought of two alternatives, the question is: which one would be better?
Let a WebView load a remote website with an offline manifest
Let a WebView load a local website in assets folder
My second question is related to the storage when offline, and once again I have two options, and I don't know which one is better:
Using the HTML5 local storage, and let HTML + javascript send data to the server when online again
Let my Android app catch the form data, and handle everything the Android way.
Any input will be very helpful. Thanks in advance.
Regarding the first question: depends on how often will you need to update your form. An online cached form can be updated quickly, while bundled pages are only updateable together with the app, and you will need to consider that both legacy and new clients can connect to your server at the same time (users will procrastinate updating).
Another aspect is portability. Do you envision an iOS version of your app, or perhaps a mobile site? If yes, then an HTML5 solution is definitely more portable. Also, debugging an app which is entirely HTML or entirely native is usually easier than a hybrid one -- you can stay within a single debugger.
Perhaps, one drawback of using HTML local storage inside WebView is that the data you save will be in a kind of a "black box" -- you will not be able to back it up easily.
[Added later] OK -- one drawback of putting your site into assets folder is that you'll have to use file: scheme in order to access it. This can lead to some cross-origin loading access related issues if you will try to mix your bundled content with content from the web. Check these WebView settings for example: setAllowFileAccessFromFileURLs, setAllowUniversalAccessFromFileURLs, setMixedContentMode.
My application have to request some RSS feeds and display the result, i want to be able to add some feeds to the RSS list without modifying the app source code.
The app users will not have the permission to modify the RSS feeds list so i can't implement it in the app.
My idea is to create an xml configuration file and host it online, so the app can access this file on start : this solution let me update the file without updating the application.
But i don't know which online service let me to do that, do you knowa some services that are dedicated for this purpose ? Any proposal will be helpful.
Thanks.
Your not being that clear on what you want. As there are many different hosting sites. It seems your looking at just something to host your app underneath the app?? Or were you looking at something else?
I am new to this. I have the Android SDK installed with Eclipse. I can work with basic activities and layouts.
I am looking to write this Android application that will;
1) Allow users to sign-in using a pre-allocated password.
2) Login and change the password.
3) Every time the user opens the app, he downloads a CSV file from a server to the SD card.
4) The app parses from the file and displays them on several activities and small frames inside the app.
Think of it as an informational application. But, I'd like to add some intelligence on top of it after I get this done.
I have read many articles and topics but none of them give me a specific approach to do this faster. I have very little time for development.
If there's a similar application that you're familiar with, I'd like to take a look at the code.
I want to know exactly (the code) on how the communication between the app and a linux based server on the web needs to be established. Right now, there's only a CSV file (or an EXCEL file - which one's better to parse? How to decide?) there.
Also, when the CSV file is up to date, I wouldn't want it to download the file again. How to prevent it?
As I said, I am new - so please be patient.
Thanks
If you are new to this and want to develop something fast, why do it the hardest way, in java? There are so many easy toolkits out there, e.g. RFO.Basic, you will be amazed how much you can achieve, fast, that way.
(You asked several questions) Easiest to parse? If you don't have Excel installed on your Android device, the CSV is of course easier to parse, needing only text tools. However, if you have a choice of formats, why not use XML? If you have never worked with XML, there is a little learning curve, but there are lots of tutorials on the web. After that, you'll never want to go back to CSV.
Your last question: how to prevent download of unchanged file? Is this about a big file? In that case start with quickly downloading the hash (checksum) of the file, so that the client can decide if the file has changed.
I'm trying to find a way to bypass the selection pop-up for podcasts and just tell android to download the file.
Currently when you open a link to a podcast a little menu pops up and has two buttons. One says download, and one says listen. Instead I want "Download" or "Cancel".
I have looked into this and I found the DownloadManager class, but sadly (I think) it is only for 2.3, and the app is being developed for 2.2.
Does anyone know how android did file downloading before this? Is there a specific intent I can pass the link to?
Thanks!
Well, without code I can only guess.
It sounds as if you have a Web View or Browser that is interpreting the url being opened based on part of the url scheme. This is causing the operating system to try to resolve activities that are available for this url. You're seeing two activities (download or listen) which are supported by activities available on the phone. In this situation you will need to overload the loading of urls using this tutorial,
Of course, without some crystal ball I can't be certain of this based on what you've said. If this is the case and you want to know how to download it. You would need to build a downloader of your own, which is possible using Java Streams, Java NIO or some of the Apache HTTP Client libraries. Based on the size of your files, it may make sense to use Buffered Java Streams with the Apache Http Client objects.
You can find an example of how to do this here.