Guest User

Untitled

a guest
May 11th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package com.napoleonit.monita.presentation.main.location
  2.  
  3. import android.app.Service
  4. import android.content.Context
  5. import android.content.Intent
  6. import android.location.Location
  7. import android.location.LocationManager
  8. import android.os.Bundle
  9. import android.os.IBinder
  10. import android.util.Log
  11. import com.google.android.gms.location.LocationListener
  12. import com.napoleonit.monita.utilities.log.MLog
  13.  
  14. /**
  15. * Created by user on 03.05.16.
  16. */
  17.  
  18.  
  19. abstract class MyService : Service() {
  20. private val TAG: String = "BOOMBOOMTESTGPS"
  21. private var mLocationManager: LocationManager = null!!
  22. private val LOCATION_INTERVAL: Long = 1000
  23. private val LOCATION_DISTANCE: Float = 10f
  24.  
  25. class locationListener : LocationListener {
  26.  
  27. var mLastLocation: LocationListener = null!!
  28.  
  29. fun LocationListener(provider: String) {
  30. MLog.d(TAG, "LocationListener " + provider);
  31. var mLastLocation = Location(provider);
  32. }
  33.  
  34. override fun onLocationChanged(location: Location?) {
  35. MLog.d(TAG, "onLocationChanged: " + location);
  36. mLastLocation.onLocationChanged(location);
  37. }
  38.  
  39. fun onProviderEnabled(provider: String) {
  40. MLog.d(TAG, "onProviderEnabled: " + provider);
  41. }
  42.  
  43. fun onProviderDisabled(provider: String) {
  44. MLog.d(TAG, "onProviderDisabled " + provider);
  45. }
  46.  
  47. fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
  48. MLog.d(TAG, "onStatusChanged " + provider);
  49. }
  50. }
  51.  
  52. var mLocationListeners = arrayOf(LocationListener { LocationManager.GPS_PROVIDER }, LocationListener { LocationManager.NETWORK_PROVIDER });
  53.  
  54. override fun onBind(arg0 : Intent):IBinder {
  55. return null!!;
  56. }
  57.  
  58. override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
  59. MLog.d(TAG, "onStartCommand");
  60. super.onStartCommand(intent, flags, startId);
  61. return START_STICKY;
  62. }
  63.  
  64. override fun onCreate() {
  65. MLog.d(TAG, "onCreate");
  66. initializeLocationManager();
  67. try {
  68. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
  69. mLocationListeners[1]);
  70. }
  71. }
  72.  
  73. private fun initializeLocationManager() {
  74. MLog.d(TAG, "initializeLocationManager");
  75. if (mLocationManager == null) {
  76. mLocationManager = applicationContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment