-4

First of all I'm a complete noob to android, and any help that you may be able to give will probably need to be in the most basic language possible to use for me to understand.

Basically I need to extend a current application with some feature. The current application already has the ability to send a SMS to the phone with a codeword + password and it will identify the GPS co-ordinates of the phone.

What I'm looking to do is have these GPS co-ordinates saved on a textfile viewable to the user sending the text. Unfortunately I have no idea what the code for this would look like. I've attempted to search the web and I was unable to find anything I had the ability to implement.

Thanks to anyone who is able to provide some assistance.

  • take a look [http://stackoverflow.com/questions/8152125/how-to-create-text-file-and-insert-data-to-that-file-on-android](http://stackoverflow.com/questions/8152125/how-to-create-text-file-and-insert-data-to-that-file-on-android) – M D May 21 '14 at 03:44
  • mail me prasannalahiru@gmail.com i will upload sourcecode – Lahiru Prasanna May 21 '14 at 03:47
  • Appreciate the response. How am I able to have GPS co-ordinates which have been identified save to that file? – user3659072 May 21 '14 at 03:49

1 Answers1

1

hope these can help you

link

http://developer.android.com/guide/topics/data/data-storage.html

code:

locationManagerNetwork = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location2 = locationManagerNetwork
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

if (location2 != null) {       
                String message = String
                        .format("Yout location : \n Longitude: %1$s \n Latitude: %2$s",
                                location2.getLongitude(), location2.getLatitude());
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG)
                        .show();

   //use here file writer if you want to write the coordinastes in a text file
            }

for writing sd card

File sdcard = Environment.getExternalStorageDirectory();
        File f = new File(sdcard, "/yourfile");

if(!f.exsist()){
f.createNewFile();
//Use outwriter here, outputstream search how to write into a tet file in java code 
}

you can also use this code

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    if (location != null) {
        long time= System.currentTimeMillis();
        String millisec = "" + time;
        double lat = location.getLatitude();
        double longe = location.getLongitude();
        loc = millisec + "\t" + lat + "\t" + longe + "\n"; 
        try {
            FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_APPEND);
            fos.write(loc.getBytes());
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Bharadwaja Bapatla
  • 3,281
  • 1
  • 12
  • 14
  • Really appreciate the reply. I'll attempt to incorporate this shortly and will post back if I run into any issues. – user3659072 May 21 '14 at 06:11
  • How is it that I'm able to see if it saved the location to the text file? I have copied that code into the eclipse, added some java exceptions etc. to remove all the errors, the application still sends / receives the text & GPS co-ordinates fine, but I can't see how to get the text file. – user3659072 May 22 '14 at 01:54