1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Saving Stats to Text File


Last Updated:

  1. grungefreak1

    grungefreak1 Member This Topic's Starter

    Joined:
    Sep 13, 2008
    Messages:
    6
    Likes Received:
    0
    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
     

    Advertisement
  2. grungefreak1

    grungefreak1 Member This Topic's Starter

    Joined:
    Sep 13, 2008
    Messages:
    6
    Likes Received:
    0
    Did I ask too much on one post?Or is none of this possible?
    any pointers are most welcome.
    gf
     
  3. Ageless Stranger

    Ageless Stranger Well-Known Member

    Joined:
    Dec 2, 2008
    Messages:
    699
    Likes Received:
    49
    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.
     
  4. grungefreak1

    grungefreak1 Member This Topic's Starter

    Joined:
    Sep 13, 2008
    Messages:
    6
    Likes Received:
    0
    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
     
  5. Ageless Stranger

    Ageless Stranger Well-Known Member

    Joined:
    Dec 2, 2008
    Messages:
    699
    Likes Received:
    49
    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
     
  6. grungefreak1

    grungefreak1 Member This Topic's Starter

    Joined:
    Sep 13, 2008
    Messages:
    6
    Likes Received:
    0
    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
     
  7. fryguy

    fryguy Member

    Joined:
    Mar 30, 2009
    Messages:
    6
    Likes Received:
    0
    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 (Text):
    1. File kmzFile = new File(Environment.getExternalStorageDirectory(),"session.kmz");
    2.                 kmzFile.createNewFile();
    3.                
    4.                 //create zip file
    5.                 ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(kmzFile));
    6.                 zipWriter = new PrintWriter(zipFile);
    7.                
    8.                 //add kml
    9.                 zipFile.putNextEntry(new ZipEntry("session.kml"));
    10.                 DOMWriter writer = new DOMWriter(zipWriter,false);
    11.                 writer.print(kml);
    12.                 zipFile.closeEntry();
    13. zipWriter.close();
    Retrieving and sending:

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

Share This Page

Loading...