Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.napoleonit.monita.presentation.main.location
- import android.app.Service
- import android.content.Context
- import android.content.Intent
- import android.location.Location
- import android.location.LocationManager
- import android.os.Bundle
- import android.os.IBinder
- import android.util.Log
- import com.google.android.gms.location.LocationListener
- import com.napoleonit.monita.utilities.log.MLog
- /**
- * Created by user on 03.05.16.
- */
- abstract class MyService : Service() {
- private val TAG: String = "BOOMBOOMTESTGPS"
- private var mLocationManager: LocationManager = null!!
- private val LOCATION_INTERVAL: Long = 1000
- private val LOCATION_DISTANCE: Float = 10f
- class locationListener : LocationListener {
- var mLastLocation: LocationListener = null!!
- fun LocationListener(provider: String) {
- MLog.d(TAG, "LocationListener " + provider);
- var mLastLocation = Location(provider);
- }
- override fun onLocationChanged(location: Location?) {
- MLog.d(TAG, "onLocationChanged: " + location);
- mLastLocation.onLocationChanged(location);
- }
- fun onProviderEnabled(provider: String) {
- MLog.d(TAG, "onProviderEnabled: " + provider);
- }
- fun onProviderDisabled(provider: String) {
- MLog.d(TAG, "onProviderDisabled " + provider);
- }
- fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
- MLog.d(TAG, "onStatusChanged " + provider);
- }
- }
- var mLocationListeners = arrayOf(LocationListener { LocationManager.GPS_PROVIDER }, LocationListener { LocationManager.NETWORK_PROVIDER });
- override fun onBind(arg0 : Intent):IBinder {
- return null!!;
- }
- override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
- MLog.d(TAG, "onStartCommand");
- super.onStartCommand(intent, flags, startId);
- return START_STICKY;
- }
- override fun onCreate() {
- MLog.d(TAG, "onCreate");
- initializeLocationManager();
- try {
- mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
- mLocationListeners[1]);
- }
- }
- private fun initializeLocationManager() {
- MLog.d(TAG, "initializeLocationManager");
- if (mLocationManager == null) {
- mLocationManager = applicationContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment