Save network location as a .txt file (Without using GPS)

前端 未结 2 884
梦谈多话
梦谈多话 2021-01-13 01:23

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. So

相关标签:
2条回答
  • 2021-01-13 01:53

    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.

    0 讨论(0)
  • 2021-01-13 01:57

    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 
    }
    
    0 讨论(0)
提交回复
热议问题