You need to add GPS data in the file name. I get the GPS data from the DataGP class. Its content is:

public class DataGPS extends Activity { private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) {// 袙 onCreate 袨袩袪袝袛袝袥携袝袦 TextView 袣袨袦袩袨袧袝袧孝蝎 袠 袩袨袥校效袗袝袦 locationManager 效袝袪袝袟 袣袨孝袨袪蝎袡 袠 袘校袛袝袦 袪袗袘袨孝袗孝鞋 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); } protected void onResume() {// 袙 onResume 袙袝楔袗袝袦 小袥校楔袗孝袝袥携 袧袗 袩袪袨袙袗袡袛袝袪袗 小 袩袨袦袨些鞋挟 袦袝孝袨袛袗 requestLocationUpdates super.onResume(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER/*孝袠袩 袩袪袨袙袗袡袛袝袪袗*/,// 袧袗 袙啸袨袛 袝袦校 袩袨袛袗衼袦 1000 * 10/*袦袠袧袠袦袗袥鞋袧袨袝 袙袪袝袦携 袟袗袩袪袨小袗 袣袨袨袪袛袠袧袗孝*/, 10/*袪袗小孝袨携袧袠袝 袨孝袨袡袛携 袧袗 袣袨孝袨袪袨袝 袨袘袧袨袙袥携挟孝小携 袣袨袨袪袛袠袧袗孝蝎*/, locationListener); } @Override protected void onPause() {//袨孝袣袥挟效袗袝袦 小袥校楔袗孝袝袥携 袦袝孝袨袛袗 removeUpdates super.onPause(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } locationManager.removeUpdates(locationListener); } private LocationListener locationListener = new LocationListener() {//LocationListener 小袥校楔袗孝袝袥鞋 袪袝袗袥袠袟校袝孝 袠袧孝袝袪肖袝袡小 locationListener 小袨 小袥袝袛校挟些袠袦袠 袦袝孝袨袛袗袦袠 @Override public void onLocationChanged(Location location) {//袦袝孝袨袛 onLocationChanged 袧袨袙蝎袝 袛袗袧袧蝎袝 袨 袦袝小孝袨 袩袨袥袨袞袝袧袠袠 showLocation(location); //袟袛袝小鞋 袙蝎袟蝎袙袗袝袦 小袙袨袡 袦袝孝袨袛 showLocation(location)袣袨孝袨袪蝎袡 袧袗 协袣袪袗袧袝 袨孝袨袘袪袨袟袠孝 袛袗袧袧蝎袝 袨 袦袝小孝袨 袩袨袥袨袞袝袧袠袠 } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderDisabled(String provider) {//校袣袗袟袗袧蝎袡 袩袪袨袙袗袡袛袝袪 袘蝎袥 袨孝袣袥挟效袨袧 袩袨袥鞋袟袨袙袗孝袝袥袝袦 } @Override public void onProviderEnabled(String provider) {//校袣袗袟袗袧蝎袡 袩袪袨袙袗袡袛袝袪 袘蝎袥 袙袣袥挟效袨袧 袩袨袥鞋袟袨袙袗孝袝袥袝袦 } }; private void showLocation(Location location) {// 袧袗 袙啸袨袛 袘袝袪衼孝 Location location 袨袩袪袝袛袝袥携袝孝 袝袚袨 袦袝孝袨袛袨袦 .getProvider() if (location == null) return; // location.getProvider(); formatLocation(location); } private String formatLocation(Location location) {// 袧袗 袙啸袨袛 袘袝袪衼孝 Location location if (location == null) //效袝孝袗袝孝 袠袟 袧袝袚袨 袛袗袧袧蝎袝 袠 袙蝎袛袗衼孝 小孝袪袨袣校 return ""; //楔袠袪袨孝袗, 袛袨袥袚袨孝袗, 袙袪袝袦携 袨袩袪袝袛袝袥袝袧袠携 return String.format( "lat = %1$.4f, lon = %2$.4f", location.getLatitude(), location.getLongitude());/*, new Date( location.getTime()));*/ } 

So add to the file name

 DataGPS dataGPS = new DataGPS(); file = new File(directory.getPath() + "/" + "photo_" + timeStamp + dataGPS + ".jpg"); 

There is a date in the file name, but in the place of latitude and longitude such nonsense is obtained:

 photo_094127_28062016cod.ru.centre_v00.MainActivity$DataGPS@4222a6b8.jpg 

What am I doing wrong ?

    1 answer 1

    When casting an object to a String type, its toString() method is called. The standard implementation of the method looks like this.

     getClass().getName() + '@' + Integer.toHexString(hashCode()) 

    Those. The string representation of an object consists of its name and a hash code, as seen in your example.

    If the DataGPS class DataGPS written by you, then you can override the toString method to your liking. Or, if the source code of this class is not available to you, when generating the file name, explicitly call get methods of this class.