当前位置: 首页>>代码示例>>C#>>正文


C# Context.GetSystemService方法代码示例

本文整理汇总了C#中Android.Content.Context.GetSystemService方法的典型用法代码示例。如果您正苦于以下问题:C# Context.GetSystemService方法的具体用法?C# Context.GetSystemService怎么用?C# Context.GetSystemService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Content.Context的用法示例。


在下文中一共展示了Context.GetSystemService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnReceive

 public override void OnReceive(Context context, Intent intent)
 {
     var str1 = intent.GetStringExtra ("team1");
     var str2 = intent.GetStringExtra ("team2");
     var count1 = intent.GetStringExtra ("count");
     var iconId = intent.GetStringExtra ("icon");
     Console.WriteLine ("Servise Start");
     PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
     PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Partial, "NotificationReceiver");
     w1.Acquire ();
     Notification.Builder builder = new Notification.Builder (context)
         .SetContentTitle (context.Resources.GetString(Resource.String.matchIsStarting))
         .SetContentText (str1+" VS. "+str2)
         .SetSmallIcon (Convert.ToInt32(iconId));
     // Build the notification:
     Notification notification = builder.Build();
     notification.Defaults = NotificationDefaults.All;
     // Get the notification manager:
     NotificationManager notificationManager = (NotificationManager)context.GetSystemService (Context.NotificationService);
     // Publish the notification:
     int notificationId = Convert.ToInt32(count1);
     notificationManager.Notify (notificationId, notification);
     w1.Release ();
     var tempd = DateTime.UtcNow;
     Console.WriteLine ("Alarm: " + tempd);
 }
开发者ID:mexaniksay,项目名称:GamePro02,代码行数:26,代码来源:AlarmM.cs

示例2: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
            PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup | WakeLockFlags.OnAfterRelease, "NotificationReceiver");
            w1.Acquire ();

            //Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();
            var nMgr = (NotificationManager)context.GetSystemService (Context.NotificationService);
            var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
            //Clicking the pending intent does not go to the Home Activity Screen, but to the last activity that was active before leaving the app
            var pendingIntent = PendingIntent.GetActivity (context, 0, new Intent (context, typeof(Home)), PendingIntentFlags.UpdateCurrent);
            //Notification should be language specific
            notification.SetLatestEventInfo (context, context.Resources.GetString(Resource.String.ReminderTitle), context.Resources.GetString(Resource.String.ReminderText), pendingIntent);
            notification.Flags |= NotificationFlags.AutoCancel;
            nMgr.Notify (0, notification);

            Vibrator vibrator = (Vibrator) context.GetSystemService(Context.VibratorService);
            if (vibrator != null)
                vibrator.Vibrate(400);

            w1.Release ();

            //check these pages for really waking up the device
            // http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up
            // https://forums.xamarin.com/discussion/7490/alarm-manager

            //it's good to use the alarm manager for tasks that should last even days:
            // http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android/
        }
开发者ID:fsoyka,项目名称:RUOK,代码行数:29,代码来源:AlarmReceiver.cs

示例3: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
            PowerManager.WakeLock w1 = pm.NewWakeLock (WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup | WakeLockFlags.OnAfterRelease, "NotificationReceiver");
            w1.Acquire ();

            //Toast.MakeText (context, "Received intent!", ToastLength.Short).Show ();
            var nMgr = (NotificationManager)context.GetSystemService (Context.NotificationService);
            //var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
            var notification = new Notification (Resource.Drawable.Icon, context.Resources.GetString(Resource.String.ReminderTitle));
            //Clicking the pending intent does not go to the Home Activity Screen, but to the last activity that was active before leaving the app
            var pendingIntent = PendingIntent.GetActivity (context, 0, new Intent (context, typeof(Home)), PendingIntentFlags.UpdateCurrent);
            //Notification should be language specific
            notification.SetLatestEventInfo (context, context.Resources.GetString(Resource.String.ReminderTitle), context.Resources.GetString(Resource.String.InvalidationText), pendingIntent);
            notification.Flags |= NotificationFlags.AutoCancel;
            nMgr.Notify (0, notification);

            //			Vibrator vibrator = (Vibrator) context.GetSystemService(Context.VibratorService);
            //			if (vibrator != null)
            //				vibrator.Vibrate(400);

            //change shared preferences such that the questionnaire button can change its availability
            ISharedPreferences sharedPref = context.GetSharedPreferences("com.FSoft.are_u_ok.PREFERENCES",FileCreationMode.Private);
            ISharedPreferencesEditor editor = sharedPref.Edit();
            editor.PutBoolean("QuestionnaireActive", false );
            editor.Commit ();

            //insert a line of -1 into some DB values to indicate that the questions have not been answered at the scheduled time
            MoodDatabase dbMood = new MoodDatabase(context);
            ContentValues insertValues = new ContentValues();
            insertValues.Put("date", DateTime.Now.ToString("dd.MM.yy"));
            insertValues.Put("time", DateTime.Now.ToString("HH:mm"));
            insertValues.Put("mood", -1);
            insertValues.Put("people", -1);
            insertValues.Put("what", -1);
            insertValues.Put("location", -1);
            //use the old value of questionFlags
            Android.Database.ICursor cursor;
            cursor = dbMood.ReadableDatabase.RawQuery("SELECT date, QuestionFlags FROM MoodData WHERE date = '" + DateTime.Now.ToString("dd.MM.yy") + "'", null); // cursor query
            int alreadyAsked = 0; //default value: no questions have been asked yet
            if (cursor.Count > 0) { //data was already saved today and questions have been asked, so retrieve which ones have been asked
                cursor.MoveToLast (); //take the last entry of today
                alreadyAsked = cursor.GetInt(cursor.GetColumnIndex("QuestionFlags")); //retrieve value from last entry in db column QuestionFlags
            }
            insertValues.Put("QuestionFlags", alreadyAsked);
            dbMood.WritableDatabase.Insert ("MoodData", null, insertValues);

            //set the new alarm
            AlarmReceiverQuestionnaire temp = new AlarmReceiverQuestionnaire();
            temp.SetAlarm(context);

            w1.Release ();

            //check these pages for really waking up the device
            // http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up
            // https://forums.xamarin.com/discussion/7490/alarm-manager

            //it's good to use the alarm manager for tasks that should last even days:
            // http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android/
        }
开发者ID:fsoyka,项目名称:RUOK,代码行数:60,代码来源:AlarmReceiverInvalid.cs

示例4: OnReceive

 public override void OnReceive(Context context, Intent intent)
 {
     var connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
     var info = connectivityManager.ActiveNetworkInfo;
     if (info != null && info.IsConnected)
     {
         //do stuff
         var wifiManager = (WifiManager)context.GetSystemService(Context.WifiService);
         var wifiInfo = wifiManager.ConnectionInfo;
         var ssid = wifiInfo.SSID;
         if (ssid == "\"jackstack\"")
         {
             var nMgr = (NotificationManager)context.GetSystemService(Context.NotificationService);
             //var notification = new Notification(Resource.Drawable.icon, $"Connected to {ssid}!");
             var pendingIntent = PendingIntent.GetActivity(context, 0, new Intent(context, typeof(MainActivity)), 0);
             //notification.SetLatestEventInfo(context, "Wifi Connected", "Wifi Connected Detail", pendingIntent);
             var notification = new Notification.Builder(context)
                 .SetSmallIcon(Resource.Drawable.icon)
                 .SetTicker($"Connected to {ssid}!")
                 .SetContentTitle("Wifi Connected")
                 .SetContentText("Wifi Connected Detail")
                 .SetContentIntent(pendingIntent)
                 .Build();
             nMgr.Notify(0, notification);
         }
     }
 }
开发者ID:chz160,项目名称:Cumulus.io,代码行数:27,代码来源:WifiConnectionMadeBroadcastReceiver.cs

示例5: OnReceive

 public override void OnReceive(Context c, Intent intent)
 {
     PowerManager pm = (PowerManager)c.GetSystemService(Context.PowerService);
     PowerManager.WakeLock wl = pm.NewWakeLock (WakeLockFlags.Partial, "Notificacion");
     wl.Acquire ();
     NotificationManager manager = (NotificationManager)c.GetSystemService (Context.NotificationService);
     Notification notification = new Notification (Resource.Drawable.icon, "Tareas pendientes");
     PendingIntent pendiente = PendingIntent.GetActivity (c, 0, new Intent (c, typeof(MainActivity)), 0);
     notification.SetLatestEventInfo (c, "Tareas pendientes", "Tienes tareas por hacer", pendiente);
     manager.Notify (0, notification);
     wl.Release ();
 }
开发者ID:icebeam7,项目名称:AdministradorTareas,代码行数:12,代码来源:Receptor.cs

示例6: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            PowerManager powerManager = (PowerManager)context.GetSystemService(Context.PowerService);
            PowerManager.WakeLock wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "Notification Reciever");
            wakeLock.Acquire();

            var notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
            var notification = new Notification(Resource.Drawable.Icon, "New Meeting");
            var pendingIntent = PendingIntent.GetActivity(context, 0, new Intent(context, typeof(SplashScreenActivity)), 0);
            notification.SetLatestEventInfo(context, "New Meeting", "There is an ACM meeting today.", pendingIntent);
            notificationManager.Notify(0, notification);
            wakeLock.Release();
        }
开发者ID:nickpeppers,项目名称:WKUACMApp,代码行数:13,代码来源:NotificationReciever.cs

示例7: QuickAction

        public QuickAction(Context context, QuickActionLayout orientation)
        {
            _context = context;
            _window = new PopupWindow(context);
            _childPos = 0;

            _window.TouchIntercepted += HandleTouchIntercepted;
            _windowManager = context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();

            _orientation = orientation;
            _inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);

            SetRootViewId(orientation == QuickActionLayout.Horizontal ? Resource.Layout.popup_horizontal : Resource.Layout.popup_vertical);
        }
开发者ID:mmowbray,项目名称:EstimoteCounter,代码行数:14,代码来源:QuickAction.cs

示例8: Initialize

 public static void Initialize(Context ctx)
 {
     var wm = ctx.GetSystemService (Context.WindowService).JavaCast<IWindowManager> ();
     var displayMetrics = new DisplayMetrics ();
     wm.DefaultDisplay.GetMetrics (displayMetrics);
     density = displayMetrics.Density;
 }
开发者ID:Andrea,项目名称:FriendTab,代码行数:7,代码来源:DensityExtensions.cs

示例9: Initialize

        public static void Initialize(Context ctx)
        {
            P2PManager.ctx = ctx;

            if (intentFilter == null)
            {
                intentFilter = new IntentFilter();

                intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
                intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
                intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
                intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);
            }
            if (manager == null)
            {
                manager = (WifiP2pManager)ctx.GetSystemService(Context.WifiP2pService);
                channel = manager.Initialize(ctx, ctx.MainLooper, null);
            }
            if (receiver == null)
            {
                receiver = new WiFiDirectBroadcastReceiver(manager, channel);
            }

            ctx.RegisterReceiver(receiver, intentFilter);
        }
开发者ID:fubar-coder,项目名称:cryptrans,代码行数:25,代码来源:P2PManager.cs

示例10: ConnectAsync

        public static async Task<ConnectionResult> ConnectAsync(Context context, Ssid ssid, TimeSpan checkInterval, TimeSpan timeout)
        {
            Logger.Verbose("WifiConnector.Connecting");

            var wifiManager = context.GetSystemService(Context.WifiService).JavaCast<WifiManager>();
            EnsureWifiEnabled(wifiManager);
            if (IsConnectedToNetwork(wifiManager, ssid))
            {
                Logger.Info($"Network {ssid} already connected");
                return ConnectionResult.AlreadyConnected;
            }

            var network = GetConfiguredNetwork(wifiManager, ssid);
            EnsureDifferentNetworksNotActive(wifiManager, network);
            EnsureNetworkReachable(wifiManager, ssid);

            ActivateNetwork(wifiManager, network);
            Reconnect(wifiManager);

            Logger.Verbose($"Connection to network {ssid} requested");
            
            var result = await WaitUntilConnectedAsync(wifiManager, network, checkInterval, timeout);
            Logger.Info(result == ConnectionResult.Connected
                ? $"Connected to {ssid.Quoted}"
                : $"Not yet connected to {ssid.Quoted}. Try increase a connection timeout");
            return result;
        }
开发者ID:t-denis,项目名称:CiscoWLC.WebAuth.Client,代码行数:27,代码来源:WifiConnector.cs

示例11: PullEventsByLocation

        public static void PullEventsByLocation(int page, int count, double longitude, double latitude, Context context, Action<EventsJson> callback)
        {
            Task<bool>.Factory.StartNew(
                                   () =>
                                   {
                                       try
                                       {


                                           var connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
                                           var activeConnection = connectivityManager.ActiveNetworkInfo;
                                           if ((activeConnection != null) && activeConnection.IsConnected)
                                           {
                                               try
                                               {
                                                   CalendarMobile.PullCurrentEventsByLocation(page, count, longitude, latitude, callback);
                                               }
                                               catch (Exception ex)
                                               {
                                                   ErrorHandler.Save(ex, MobileTypeEnum.Android, context);
                                               }
                                           }


                                       }
                                       catch (Exception exception)
                                       {
                                           ErrorHandler.Save(exception, MobileTypeEnum.Android, context);
                                       }
                                       return true;
                                   });

        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:33,代码来源:Calendar.cs

示例12: CreateNotifications

		private void CreateNotifications(Context context, string action, bool isMessageNeeded = true, bool isToastNeeded = true)
		{
			#if DEBUG
			try {
				if (isMessageNeeded)
				{
					Notification notification = new Notification.Builder(context)
						.SetContentTitle ("BluetoothNotify intent received " + action)
						.SetContentText ("message sent at" + System.DateTime.Now.ToLongTimeString ())
						.SetSmallIcon (Resource.Drawable.icon)
						.Build ();

					NotificationManager nMgr = (NotificationManager)context.GetSystemService (Android.Content.ContextWrapper.NotificationService);
					nMgr.Notify (0, notification);
				}

				if (isToastNeeded)
				{
					var myHandler = new Handler ();
					myHandler.Post (() =>  {
						Toast.MakeText (context, "BluetoothNotify intent received " + action, ToastLength.Long).Show ();
					});
				}
				
			} catch (Exception ex) {
				Log.Info ("com.tarabel.bluetoothnotify", "CreateNotification error in IntentReceiver " + ex.ToString());
			}
			#endif
		}
开发者ID:valtarakanov,项目名称:BluetoothNotify,代码行数:29,代码来源:IntentReceiver.cs

示例13: SetAlarm

 public void SetAlarm(Context context)
 {
     AlarmManager alarmMgr = (AlarmManager)context.GetSystemService(Context.AlarmService);
     Intent intent = new Intent(context, this.Class);
     PendingIntent alarmIntent = PendingIntent.GetBroadcast(context, 0, intent, 0);
     //here I have to figure out what time it is now and what would be an appropriate time for the new alarm
     //in which time window are we now? set an alarm in the next one (random). Have it go off at least 11 minutes
     //before the next window to ensure that we will end up here again even if the invalidation timer goes off as well
     //use five 2.5 h windows starting from 9 and ending at 21.30
     //This returns the total amount of hours since midnight as a fraction, meaning that 16:30 is 16.5:
     //DateTime.Now.TimeOfDay.TotalHours
     double tempNow = DateTime.Now.TimeOfDay.TotalHours;
     double timeLeftTillNextWindow = 0;
     if ((tempNow >= 0f) & (tempNow < 9f))
         timeLeftTillNextWindow = 9f - tempNow;
     if ((tempNow >= 9f) & (tempNow < 11.5f))
         timeLeftTillNextWindow = 11.5f - tempNow;
     if ((tempNow >= 11.5f) & (tempNow < 14f))
         timeLeftTillNextWindow = 14f - tempNow;
     if ((tempNow >= 14f) & (tempNow < 16.5f))
         timeLeftTillNextWindow = 16.5f - tempNow;
     if ((tempNow >= 16.5f) & (tempNow < 19f))
         timeLeftTillNextWindow = 19f - tempNow;
     if ((tempNow >= 19f) & (tempNow < 24f))
         timeLeftTillNextWindow = 24f - tempNow + 9f; //wait till next morning
     //add a random amount between 5 minutes and (2.5 hours - 11 minutes = 150 - 11 = 139 minutes)
     Random rnd = new Random(); //generator is seeded each time it is initialized
     double offset = (double) rnd.Next(5, 139);
     //add the times
     offset += timeLeftTillNextWindow * 60; //times 60 to convert from hours to minutes
     //truncated by converting to int
     long offsetLong = (int)offset;
     //System.Console.WriteLine ("Time Left: " + timeLeftTillNextWindow.ToString () + " Random + Time: " + offsetLong.ToString ());
     alarmMgr.Set(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + offsetLong * 60 * 1000, alarmIntent);
 }
开发者ID:fsoyka,项目名称:RUOK,代码行数:35,代码来源:AlarmReceiverQuestionnaire.cs

示例14: ToPixels

 public static int ToPixels(Context context, float dips)
 {
     DisplayMetrics metrics = new DisplayMetrics();
     var wm = context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
     wm.DefaultDisplay.GetMetrics(metrics);
     return (int) (dips*((float) metrics.DensityDpi/160)); // px = dp * (dpi / 160)
 }
开发者ID:TheJaniceTong,项目名称:Judo-Xamarin,代码行数:7,代码来源:UiUtils.cs

示例15: CancelAlarm

 public void CancelAlarm(Context context)
 {
     Intent intent = new Intent(context, this.Class);
     PendingIntent sender = PendingIntent.GetBroadcast(context, 0, intent, 0);
     AlarmManager alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService);
     alarmManager.Cancel(sender);
 }
开发者ID:nickpeppers,项目名称:WKUACMApp,代码行数:7,代码来源:NotificationReciever.cs


注:本文中的Android.Content.Context.GetSystemService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。