5

I am a beginner in android programming. My Graduate project is about tracking a mobile device and i need the code to save the location( Without using GPS) as a text file. Someone suggest me the codes for doing that. It will be a great help for me.

Midhun Sivaraj
  • 493
  • 5
  • 13
  • 2
    Please search before asking a question, theres already answer for this available http://stackoverflow.com/questions/1756296/android-writing-logs-to-text-file http://stackoverflow.com/questions/5844579/how-to-write-to-an-external-text-file-in-android http://stackoverflow.com/questions/4580683/android-java-writing-text-file-to-sd-card – Ruuhkis Mar 16 '12 at 08:36
  • @Ruuhkis Thank u. But my project needs to save a txt file with network location details. Kindly help me. – Midhun Sivaraj Mar 16 '12 at 08:40
  • You can easily save the network details on text file just like you can print it out. see below – Ruuhkis Mar 16 '12 at 09:38

2 Answers2

2

Try this.

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 coordinates 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 file in java code 
}
Tugrul
  • 1,760
  • 4
  • 24
  • 39
-1

only way to do that is to play with telephony manager and see what kind of information you can get about cell tower or network. Every network tower have unique id to it and from that you might be able to get an approx estimation depending upon signal strength and stuff of person's location.

I bet it'll be fun and tricky business.

Mayank
  • 8,777
  • 4
  • 35
  • 60