Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            BluetoothLowEnergyAdapter.InitActivity(this);
            UserDialogs.Init(this);
            Forms.Init(this, bundle);

            new Timer().Schedule(
                new TimerAction(
                    () =>
            {
                RunOnUiThread(
                    () =>
                {
                    if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Bluetooth) !=
                        Permission.Granted)
                    {
                        if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.Bluetooth))
                        {
                            UserDialogs.Instance.Alert(
                                "Yes should show rationale for Bluetooth",
                                "ShouldShowRequestPermissionRationale");
                        }
                        else
                        {
                            Log.Info("Requesting permission for Bluetooth");
                            ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.Bluetooth }, 24112);
                        }
                    }
                    else
                    {
                        Log.Info("Already have permission for Bluetooth");
                    }

                    if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.BluetoothAdmin) !=
                        Permission.Granted)
                    {
                        if (ActivityCompat.ShouldShowRequestPermissionRationale(
                                this,
                                Manifest.Permission.BluetoothAdmin))
                        {
                            UserDialogs.Instance.Alert(
                                "Yes should show rationale for BluetoothAdmin",
                                "ShouldShowRequestPermissionRationale");
                        }
                        else
                        {
                            Log.Info("Requesting permission for BluetoothAdmin");
                            ActivityCompat.RequestPermissions(
                                this,
                                new[] { Manifest.Permission.BluetoothAdmin },
                                24113);
                        }
                    }
                    else
                    {
                        Log.Info("Already have permission for BluetoothAdmin");
                    }
                });
            }),
                12000);

            LoadApplication(new FormsApp(BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext)));
        }