Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. public class DataGPS extends Activity {
  2.  
  3. private LocationManager locationManager;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {// В onCreate ОПРЕДЕЛЯЕМ TextView КОМПОНЕНТЫ И ПОЛУЧАЕМ locationManager ЧЕРЕЗ КОТОРЫЙ И БУДЕМ РАБОТАТЬ
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  10. }
  11.  
  12. protected void onResume() {// В onResume ВЕШАЕМ СЛУШАТЕЛЯ НА ПРОВАЙДЕРА С ПОМОЩЬЮ МЕТОДА requestLocationUpdates
  13. super.onResume();
  14.  
  15. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  16. // TODO: Consider calling
  17. // ActivityCompat#requestPermissions
  18. // here to request the missing permissions, and then overriding
  19. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  20. // int[] grantResults)
  21. // to handle the case where the user grants the permission. See the documentation
  22. // for ActivityCompat#requestPermissions for more details.
  23. return;
  24. }
  25. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER/*ТИП ПРОВАЙДЕРА*/,// НА ВХОД ЕМУ ПОДАЁМ
  26. 1000 * 10/*МИНИМАЛЬНОЕ ВРЕМЯ ЗАПРОСА КООРДИНАТ*/, 10/*РАСТОЯНИЕ ОТОЙДЯ НА КОТОРОЕ ОБНОВЛЯЮТСЯ КООРДИНАТЫ*/, locationListener);
  27. }
  28.  
  29. @Override
  30. protected void onPause() {//ОТКЛЮЧАЕМ СЛУШАТЕЛЯ МЕТОДА removeUpdates
  31. super.onPause();
  32. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  33. // TODO: Consider calling
  34. // ActivityCompat#requestPermissions
  35. // here to request the missing permissions, and then overriding
  36. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  37. // int[] grantResults)
  38. // to handle the case where the user grants the permission. See the documentation
  39. // for ActivityCompat#requestPermissions for more details.
  40. return;
  41. }
  42. locationManager.removeUpdates(locationListener);
  43. }
  44.  
  45. private LocationListener locationListener = new LocationListener() {//LocationListener СЛУШАТЕЛЬ РЕАЛИЗУЕТ ИНТЕРФЕЙС locationListener СО СЛЕДУЮЩИМИ МЕТОДАМИ
  46.  
  47. @Override
  48. public void onLocationChanged(Location location) {//МЕТОД onLocationChanged НОВЫЕ ДАННЫЕ О МЕСТО ПОЛОЖЕНИИ
  49. showLocation(location); //ЗДЕСЬ ВЫЗЫВАЕМ СВОЙ МЕТОД showLocation(location)КОТОРЫЙ НА ЭКРАНЕ ОТОБРОЗИТ ДАННЫЕ О МЕСТО ПОЛОЖЕНИИ
  50. }
  51.  
  52. @Override
  53. public void onStatusChanged(String provider, int status, Bundle extras) {
  54.  
  55. }
  56.  
  57. @Override
  58. public void onProviderDisabled(String provider) {//УКАЗАНЫЙ ПРОВАЙДЕР БЫЛ ОТКЛЮЧОН ПОЛЬЗОВАТЕЛЕМ
  59.  
  60. }
  61.  
  62. @Override
  63. public void onProviderEnabled(String provider) {//УКАЗАНЫЙ ПРОВАЙДЕР БЫЛ ВКЛЮЧОН ПОЛЬЗОВАТЕЛЕМ
  64.  
  65. }
  66.  
  67.  
  68. };
  69.  
  70. private void showLocation(Location location) {// НА ВХОД БЕРЁТ Location location ОПРЕДЕЛЯЕТ ЕГО МЕТОДОМ .getProvider()
  71. if (location == null)
  72. return;
  73. // location.getProvider();
  74. formatLocation(location);
  75. }
  76.  
  77. private String formatLocation(Location location) {// НА ВХОД БЕРЁТ Location location
  78. if (location == null) //ЧЕТАЕТ ИЗ НЕГО ДАННЫЕ И ВЫДАЁТ СТРОКУ
  79. return ""; //ШИРОТА, ДОЛГОТА, ВРЕМЯ ОПРЕДЕЛЕНИЯ
  80. return String.format(
  81. "lat = %1$.4f, lon = %2$.4f",
  82. location.getLatitude(), location.getLongitude());/*, new Date(
  83. location.getTime()));*/
  84. }
  85.  
  86. DataGPS dataGPS = new DataGPS();
  87. file = new File(directory.getPath() + "/" + "photo_"
  88. + timeStamp + dataGPS + ".jpg");
  89.  
  90. photo_094127_28062016cod.ru.centre_v00.MainActivity$DataGPS@4222a6b8.jpg
  91.  
  92. getClass().getName() + '@' + Integer.toHexString(hashCode())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement