Beispiel #1
0
        public static Intent StartService(global::Android.Content.Context context)
        {
            Intent serviceIntent = new Intent(context, typeof(AndroidSensusService));

            // after android 26, starting a foreground service requires the use of StartForegroundService rather than StartService.
            // in either case, the service itself will call StartForeground after it has started. more info:
            //
            //     https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent)
            //
            // also see notes on backwards compatibility for how the compiler directives are used below:
            //
            //    see the Backwards Compatibility article for more information
#if __ANDROID_26__
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                context.StartForegroundService(serviceIntent);
            }
            else
#endif
            {
                context.StartService(serviceIntent);
            }

            return(serviceIntent);
        }
 public override void OnReceive(global::Android.Content.Context context, Intent intent)
 {
     if (intent.Action == Intent.ActionBootCompleted)
     {
         context.StartService(new Intent(context, typeof(AndroidSensusService)));
     }
 }