• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Saving Stats to Text File

Hi,

I would be an intermediate level Java programmer (more of a hobbyist). I want to create an app for android that counts stats during a football game. This is roughly the functionality:

1.User presses buttons representing each type of stat e.g. #1 for score, #2 for lost posession of ball etc. (ideally it would be on a touchscreen phone and the user could use a stylus to touch buttons on the screen -by the way, would I have to program differently for a touchscreen? or is that a hardware thing?)

2.Each time a number is pressed, it's written to a text file on the phone or into a database (sqllite or whatever).

3. the text file can then be sent in a message to another android enabled phone.

Is it possible to test the existance of this text file on the android emulator?

Is all this possible without being an advance Java programmer? Any guidance would be welcome and I realise this is a broad definition of the program.

GF
 
Hi

I'm not a java programmer, just an ageing c/c++ developer. But from experience you are better using an SQL database to hold the information you want to store. You won't have to check for the existence of the file, the database will always be there. On the downside, if you dont know SQL you will have to learn, it's not that difficult just an extra learning curve. But it will be worth it I promise.
 
Hi

I'm not a java programmer, just an ageing c/c++ developer. But from experience you are better using an SQL database to hold the information you want to store. You won't have to check for the existence of the file, the database will always be there. On the downside, if you dont know SQL you will have to learn, it's not that difficult just an extra learning curve. But it will be worth it I promise.

Thanks. I don't mind writing to an sql database and then extracting the contents and writing them to a text file whichever's easier. I just need to be able to send a text file to another phone though. So I kinda thought the overhead would be a bit much writing to a database for each event. I know SQL so that wouldn't be a problem. do you know what I mean?
GF
 
If you want to send a text file to another phone you will have to set up a protocol for sending and receiving. To do that you would have to first read in the contents of the text file, send it and then on the receiving end opening up a new file and writing the contents to the file. I dont think there is an existing protocol to send files from one device for another so you will have to make your own
 
Thanks. But I mean I just want to write to a text file on my phone. when writing is over, the file is just saved as a file on my phone. the core phone functionality takes care of sending a mm message where I can attach this text file.

So I guess what i'm saying, is I just basically want to write from my application to a text file on my phone. that's it.

Surely this is simple enough? I was thinking that the IO classes in the Java api would have an equivalent in the android api?

GF
 
Here's an example of writing a file (zip in this case) to the sd card and retrieving it to send via email:

Writing:
Code:
File kmzFile = new File(Environment.getExternalStorageDirectory(),"session.kmz"); 
                kmzFile.createNewFile();
                
                //create zip file
                ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(kmzFile));
                zipWriter = new PrintWriter(zipFile);
                
                //add kml
                zipFile.putNextEntry(new ZipEntry("session.kml"));
                DOMWriter writer = new DOMWriter(zipWriter,false);
                writer.print(kml);
                zipFile.closeEntry();
zipWriter.close();
Retrieving and sending:

Code:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/session.kmz"));
                sendIntent.setType("application/vnd.google-earth.kmz");
 
Back
Top Bottom