예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)

        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            Forms.Init(this, savedInstanceState);

            permissionService = new PermissionService(this);
            callAndSms        = new CallAndSms(this);
            monitor           = new Monitor(this, callAndSms);

            // deactivated and not used in Services/callAndSms atm
            // TelephonyManager telephonyManager = (TelephonyManager)GetSystemService(Context.TelephonyService);
            // telephonyManager.Listen(callAndSms, PhoneStateListenerFlags.CallState);

            LoadApplication(new App());
            permissionService.CheckBuildAndPermissions();

            // This event fires when the ServiceConnection lets the client (our App class) know that
            // the Service is connected. We use this event to start updating the UI with location
            // updates from the Service
            LocationHandler.Current.LocationServiceConnected += (sender, e) =>
            {
                Log.Debug(TAG, "ServiceConnected Event Raised");
                // notifies us of location changes from the system
                LocationHandler.Current.LocationService.LocationChanged += HandleLocationChanged;
                //notifies us of user changes to the location provider (ie the user disables or enables GPS)
                LocationHandler.Current.LocationService.ProviderDisabled += HandleProviderDisabled;
                LocationHandler.Current.LocationService.ProviderEnabled  += HandleProviderEnabled;
                // notifies us of the changing status of a provider (ie GPS no longer available)
                LocationHandler.Current.LocationService.StatusChanged += HandleStatusChanged;
            };

            Log.Debug(TAG, "OnCreate: Location app is coming to life.");


            // from btnActivate
            MessagingCenter.Subscribe <HomeViewModel>(this, "Activate", (sender) =>
            {
                Console.WriteLine("STARTING Monitor");
                monitor.StartMonitor();
            });


            MessagingCenter.Subscribe <HomeViewModel>(this, "Deactivate", (sender) =>
            {
                Console.WriteLine("STOPPING Monitor");
                monitor.StopMonitor();
            });
        }