Read/write files on server from Android - android

I'm working on a small project for fun, which involves Android and a web server.
I want some suggestion on the protocol/model to use that is best suited for the following scenario.
Server side
I have setup the following 5 components:
A config file rule.csv which contains 6 columns and about 20 rows. Each row in that file a rule.
A "switch" file RUN.on or RUN.off
A Java program that runs according to those rules, if RUN.on exists
A cronjob that runs the Java program every 5min.
A PHP page. control.php?run=on will rename RUN.off to RUN.on
control.php?run=off will set RUN.off
On Android
An app that submits to control.php to change the running status.
Goal
Now I want to add a feature to that android app, such that I can view and add/remove the rule in rule.csv. That requires a Android <--> Server <--> File communication. However, getting the whole file using PHP, and transfer it back after editing does not seem to be a good way in this case.
Since this is a project just for fun, getting it to work is not my priority; I'd like to look for a good model that handles this kind of task and I'm willing to learn other languages if necessary. Any advise?

I'm guessing the rule file is kinda big or you would just transfer it.
Adding a new rule seems pretty simple - enter the data on the Android and send the rule to the server. But how do you want the Android user to pick the rule to remove? Can you just transfer the names of all of the rules, let the user choose the rule, and then just send the rule name back?

Related

How to use XQuery in Android to query data from an XML file

I have an XML file that I want to extract data from using XQuery.
So far, the only library I found that allows such thing is MXQuery but the project seems to be abandonned.
Is there any other way to make XQuery work on Android ?
I have started building an XQuery app months ago. You would enter a query directly in the app and have it evaluated there. I was thinking it could become almost like an IDE, with one big query text field filling the screen, and then you click run and it shows the XML result.
Unfortunately urgent matters have happened and I have not gotten further than setting up the compiler for an empty project directory :( (huge annoyance, I set it up with ant and Sherlock-activity, and then those became deprecated and I had to start over with gradle and ActionbarActivity)
Earlier I made a command line tool that seems to run on Android, but you need a terminal emulator app. (afair I have fixed the memory issue mentioned in the later comments)
I also made an app for public libraries to automatically renew all books that you have lend from the library. It keeps a history of lend books and you can search that history, e.g. to get a list of all books that you have lend about a certain topic. Or find the book that you have lend the most often. The twist is you search with XQuery. Normal people enter $books[title = "foo"], but you can write serialize(<foo>bar</foo>) or doc("file:///whatever")/foo to run any XQuery on any local file inside the app. However, the entire query has to fit in one line, is not saved and the app is in German. (it will ask for the username/password of your public library account, but accepts an empty username, too).

Android app - generate a non-editable report

I am new to Android development and would like some advice from some more experience developers.
The app I am developing is effectively a form for servicing products (i.e. does x work, does y work etc.. ). Once the form has been completed a "report" of some kind needs to be generated in a non-editable format! Initially I was thinking to display a confirmation page and when confirmed by the user simply screenshot the report, however I realise this is a hacky solution and would be rather limiting! So basically I would like some input on what options I have to implement such a feature! To be clear the output file MUST be non-editable... i.e. an image file or pdf!
Also FYI - the report file will be uploaded to a dropbox/a specified folder.
PDF files seem to be a good solution for you. I would rather create a Web Service to deliver the pdf, because some devices will be really slow creating a pdf, but if you decide to take a client approach, take a look at:
http://code.google.com/p/droidtext/
http://sourceforge.net/p/itext/code/5420/tree/tags/iText_2_1_7

Configuration file in Android. Does that exist?

I have some configuration I want to save it in my Android application and read it whenever I need , for instance, the server URL that it should try to access like that.
Is there any similar mechanism like web.config in ASP.NET available in Android?
A central configuration file that can be set up manually and then read by the application? Any help would be appreciated!
We use a .properties file in assets folder. It works out very well for us as we support multiple carriers with this, write to it (in case some values, sent from server, need to change. This is done at app start time, thus making our code configurable from server).
You can throw things like that into your strings.xml file. But, since you can't actually modify these values in real-time (since it's a distributed application rather than running on a server), throwing it into a constants class is quite acceptable.
Use Shared Preferences.
Here's a link Shared Preferences
You can use sq lite database files for it. You have a native API to read and write those and on top of that a command line tool.
If you want to create an XML file instead, then it's no different than any other xml file (unless you are thinking about the Shared Preferences, which use an xml format to save the data, but I believe it's not the best API for your application).
I was stumped on this too, but came across Managed Configurations in the Android documentation.
Managed configurations, previously known as application restrictions, allow the enterprise administrator to remotely specify settings for apps. This capability is particularly useful for enterprise-approved apps deployed to a managed profile.
It allows you to set a default value in case you rather not getting into the enterprise admistration business but leaves that option open for the future.
There is a caveat. This only works if your app is registered for EMM. Otherwise you will retrieve an empty map of restrictions.

Create PDF / Word (Doc) file within app

Is there a definitive method of creating either a PDF or a MS Word Doc file within the app and email it immediately (and possibly, also store it).
I have been trying for quite some time and have found out the JAVA libraries: apwlibrary and iText. But both of them dont provide any tutorials of sorts.
Could anyone point me in the right direction?
EDIT: Come to think of it, is could an online PDF generator be used, first by sending the data to the service, then retrieve the result and save it on the phone?
I would recommend apache fop http://xmlgraphics.apache.org/fop/
you can use standard FOP to generate pdf.
Unless it is a core feature of your device to create a pdf file I would suggest not to do it yourself. Adding PDF creation is going to be quite a lot of work potentially depending on your performance needs. Java libraries will be easier to add but less performant. Native libraries combined with Java will be more hazzle to maintain build and bug fixing wise.
If you just need to email some information why dont you create a message text in html and use a intent to email it with the build in email program instead? Or if you want you could e.g. put the PDF generation on a server and just email a link..
I'm working right now with JasperReports, an open source library to create reports in Java and export them to PDF, DOC, XLS... Using it in conjunction with iReport to create a group of templates makes it really easy to create files filled with content from different types of sources (I'm using JavaBeans).
If you don't like the idea of having static templates (That's a bit annoying depending on your needs), you can always take a look at DynamicJasper (The examples on the website are great).
Good Luck!
I have used Apache POI. It seemed to work well. http://poi.apache.org/
This actually, http://poi.apache.org/hwpf/

About sqlite use

There are some things my application needs to do on first start up(first startup after update) . These actions could be described in a .txt file and then when it is the case read the file and do according to it ,or on the other hand (I lean to use this option) a sqlite database could be used to store the information . The apk file would be shipped with an .txt file/prebuild sql db stored in res/raw or res.asset and then copied into proper space and used. This I have figured out how !, though I'm not sure which option of this two would be the fittest ? One thing that is unclear to me is how could sqlite version mismatch affect me, and if it serious enough to take into consideration ? I 'm using Android api level 4 (Android 1.6) and the future application might be used on several different devices , with different api levels.
These actions could be described in a
.txt file and then when it is the case
read the file and do according to it
,or on the other hand (I lean to use
this option) a sqlite database could
be used to store the information .
Or, they could be implemented in Java.
Well the actions that the application
needs to perform on install / after
update , according to the update
version and the pre update version of
the application
Why not just implement this as regular Java code in your app?
Or, as Albert Einstein wrote, in homage to Occam's Razor: "Make everything as simple as possible, but not simpler."

Categories

Resources