示例#1
0
        public bool StartService()
        {
            var myserviceintent = new Android.Content.Intent(context, Java.Lang.Class.FromType(typeof(MyService)));

            Android.Content.ComponentName componentName;
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                componentName = context.StartForegroundService(myserviceintent);
            }
            else
            {
                componentName = context.StartService(myserviceintent);
            }

            SetServiceActive(context, componentName != null);

            return(componentName != null);
        }