/// <summary> /// /// </summary> /// <param name="bundle"></param> async protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); //Get object of this class to show data in broadc GelLocation.instance = this; SetContentView(Resource.Layout.GetLocation); _locationText = FindViewById<TextView>(Resource.Id.currentLocationTextView); _addressText = FindViewById<TextView>(Resource.Id.addressTextView); _lastKnownLocation = FindViewById<TextView>(Resource.Id.lastLocationTextView); _lastTimeStamp = FindViewById<TextView>(Resource.Id.lastTwoTimeStamp); _listOfProvider = FindViewById<TextView>(Resource.Id.providerList); _traceLocationButton = FindViewById<Button>(Resource.Id.traceLocationButton); _idView = FindViewById<TextView>(Resource.Id.idView); _traceLocationButton.Click += _traceLocationButton_Click; //Get shared preferences data sharedPreferenceId = JsonConvert.DeserializeObject<Coordinates>(Intent.GetStringExtra("user")); //Show id _idView.Text = "User Id: " + sharedPreferenceId.uniqueId.ToString(); //Get device id for currentr user getDeviceId(); //Get last known location of current user latlon.uniqueId = sharedPreferenceId.uniqueId; latlon = await WebRequestServer.GetLastKnownLocation(latlon); //if respond is null if (latlon == null) { _lastKnownLocation.Text = string.Format("Latitude: " + "N\\A" + "\nLongitude: " + "N\\A" + "\nAccuracy: " + "N\\A" + "\nDatetime: " + "N\\A" + "\nBearing: " + "N\\A" + "\nAltitude: " + "N\\A"); } //Otherwise perform else _lastKnownLocation.Text = string.Format("Latitude: " + latlon.Latitude + "\nLongitude: " + latlon.Longitude + "\nAccuracy: " + latlon.Accuracy + "\nDateTime: " + latlon.timeStamp + "\nBearing: " + latlon.Bearing+ "\nAltitude: " + latlon.altittude); } catch (Exception ex) { throw; } }
/// <summary> /// /// </summary> /// <param name="myactivity"></param> public MyLocationReceiver(GelLocation myactivity) { _myactivity = myactivity; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="intent"></param> public override void OnReceive(Context context, Intent intent) { try { //Geting instance of base class _myactivity = GelLocation.instance; if (GelLocation.isRunning == true) { } else { return; } if (intent.Action == GRID_STARTED) { //_myactivity.latlon = JsonConvert.DeserializeObject<Coordinates>(intent.GetStringExtra("cor")); //_myactivity.RunOnUiThread(() => //{ string provider = intent.GetStringExtra("provider"); string cordinates = intent.GetStringExtra("cordinates"); string timeInterval = intent.GetStringExtra("timeStamp"); if (timeInterval != null) { timeStamp = JsonConvert.DeserializeObject<DateTime[]>(intent.GetStringExtra("timeStamp")); _myactivity._lastTimeStamp.Text = ""; for(int i = 0; i < timeStamp.Length; i++) { _myactivity._lastTimeStamp.Text += string.Format(timeStamp[i].ToString() + "\n"); } } if (provider != null) { _myactivity.latlon = JsonConvert.DeserializeObject<Coordinates>(intent.GetStringExtra("provider")); _myactivity._listOfProvider.Text = ""; if (_myactivity.latlon.provider.Count == 0) { _myactivity._listOfProvider.Text = "N\\A"; } for (int i = 0; i < _myactivity.latlon.provider.Count; i++) { _myactivity._listOfProvider.Text += String.Format(_myactivity.latlon.provider[i]); if (i < _myactivity.latlon.provider.Count - 1) { _myactivity._listOfProvider.Text += "\n"; } } } else if (cordinates != null) { _myactivity.latlon = JsonConvert.DeserializeObject<Coordinates>(intent.GetStringExtra("cordinates")); _myactivity._locationText.Text = String.Format("Latitude: {0} \nLongitude: {1} \nAccuracy: {2} \nSpeed: {3} \nDateTime: {4} \nBearing: {5} \nAltitude: {6}", _myactivity.latlon.Latitude, _myactivity.latlon.Longitude, _myactivity.latlon.Accuracy, _myactivity.latlon.speed,_myactivity.latlon.timeStamp,_myactivity.latlon.Bearing,_myactivity.latlon.altittude); _myactivity.streetAddress(_myactivity.latlon); } //}); } } catch (Exception ex) { throw; // Toast.MakeText(Android.App.Application.Context, "GetLocation-OnReceive" + ex.Message, ToastLength.Long).Show(); } }
/// <summary> /// Start service on start up /// </summary> protected override void OnStart() { try { base.OnStart(); isRunning = true; Intent intent = new Intent(this, typeof(BackgroundService)); //Send preferences to the service to send id to server //intent.PutExtra("userId", sharedPreferenceId.uniqueId.ToString()); StartService(intent); GelLocation.instance = this; } catch (Exception ex) { throw; } }