Ejemplo n.º 1
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            StorageService   storage   = new StorageService();
            BluetoothService bluetooth = new BluetoothService();

            App.BluetoothStartedEnabled = bluetooth.IsEnabled;
            Location.RequestEnableGPS();

            var a = FirebaseApp.InitializeApp(this);

            player = MediaPlayer.Create(this, Resource.Raw.Stop);
            Thread TurnOnAndConnect = new Thread(() =>
            {
                try
                {
                    if (!App.BluetoothStartedEnabled)
                    {
                        bluetooth.Enable();
                        Thread.Sleep(3000);
                    }

                    if (!string.IsNullOrWhiteSpace(storage.GUID))
                    {
                        var adapter = CrossBluetoothLE.Current.Adapter;
                        var aa      = adapter.ConnectToKnownDeviceAsync(new Guid(storage.GUID)).Result;
                    }

                    if (!string.IsNullOrWhiteSpace(storage.Address))
                    {
                        bluetooth.ConnectToSensor(storage.Address, true);
                    }
                }
                catch (System.Exception ex)
                {
                    string title = this.GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name;
                    if (BalizaFacil.App.Instance != null)
                    {
                        BalizaFacil.App.Instance.UnhandledException(title, ex);
                    }
                }
            });

            TurnOnAndConnect.Priority = System.Threading.ThreadPriority.Highest;
            TurnOnAndConnect.Name     = nameof(TurnOnAndConnect);

            TurnOnAndConnect.Start();


            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            //RequestPermissions(new string[] { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation }, 0);
            Xamarin.Essentials.Platform.Init(this, bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);

            Instance = this;
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            ZXing.Net.Mobile.Forms.Android.Platform.Init();
            ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);

            DisplayMetrics displayMetrics = new DisplayMetrics();

            WindowManager.DefaultDisplay.GetRealMetrics(displayMetrics);
            App.ScreenHeight = (int)(Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
            App.ScreenWidth  = (int)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);
            App.HeightPixels = displayMetrics.HeightPixels;
            App.WidthPixels  = displayMetrics.WidthPixels;
            App.IsAndroidSDKBelowMarshmallow = Build.VERSION.SdkInt < BuildVersionCodes.M;

            AppDomain.CurrentDomain.UnhandledException  += OnCurrentDomainUnhandledException;
            TaskScheduler.UnobservedTaskException       += OnTaskSchedulerOnUnobservedTaskException;
            AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidEnvironmentOnUnhandledException;

            LoadApplication(new App());
        }