Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////// Implemintation to initialize and Stop Service/////////////////////////////////////////////////
- context.startService(Intent(this,LocationService()::class.java));
- context.stopService(Intent(this,LocationService()::class.java));
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////Location Service//////////////////////////////////////////////////////////
- class LocationService : Service()
- {
- var gpsTracker : GpsTracker? = null;
- var context : Context? = null;
- override fun onBind(intent: Intent): IBinder?
- {
- return null
- }
- override fun onCreate()
- {
- try{
- context = this;
- Log.e("Service","Service Created");
- gpsTracker = GpsTracker(this, object : OnLocationUpdated
- {
- override fun locationChange(location: Location)
- {
- sendLocationToSocket(location);
- }
- });
- } catch (e: Exception){
- }
- }
- private fun sendLocationToSocket(location:Location)
- {
- if(gpsTracker != null && gpsTracker!!.ifICanGetLocation() && location != null)
- {
- Log.e("LocationLat","${location.latitude}");
- Log.e("LocationLon","${location.longitude}");
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment