コード例 #1
0
        public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
        {
            var t = new Java.Lang.Thread(() =>
            {
                _cts = new CancellationTokenSource();

                Task.Run(() =>
                {
                    try
                    {
                        var counter = new ScreenReceiver();
                        //counter.ExecutePost(_cts.Token).Wait();
                    }
                    catch (Android.Accounts.OperationCanceledException)
                    {
                    }
                    finally
                    {
                        if (_cts.IsCancellationRequested)
                        {
                        }
                    }
                }, _cts.Token);
            }
                                         );

            t.Start();
            return(StartCommandResult.RedeliverIntent);
        }
コード例 #2
0
        protected async override void OnCreate(Bundle bundle)
        {
            await TryToGetPermissions();

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


            base.OnCreate(bundle);
            //var intent = new Intent(ApplicationContext, typeof(PowerButtonService));
            //var source = PendingIntent.GetBroadcast(ApplicationContext, 0, intent, 0);

            Rg.Plugins.Popup.Popup.Init(this, bundle);

            Xamarin.Forms.Forms.Init(this, bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            Xamarin.FormsMaps.Init(this, bundle);
            Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
            Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
            LoadApplication(new App());

            LocationManager locationManager = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);



            if (locationManager.IsProviderEnabled(LocationManager.GpsProvider) == false)
            {
                // ShowGPSDisabledAlertToUser();
            }
            IntentFilter filter = new IntentFilter(Intent.ActionScreenOn);

            filter.AddAction(Intent.ActionScreenOff);
            filter.AddAction(Intent.ActionUserPresent);
            ScreenReceiver myReceiver = new ScreenReceiver();

            RegisterReceiver(myReceiver, filter);
        }