Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/molinch/Xam.Plugins.ManageSleep
Manage auto sleep / auto lock in all platforms
https://github.com/molinch/Xam.Plugins.ManageSleep
Last synced: 3 months ago
JSON representation
Manage auto sleep / auto lock in all platforms
- Host: GitHub
- URL: https://github.com/molinch/Xam.Plugins.ManageSleep
- Owner: molinch
- License: mit
- Created: 2015-01-01T13:31:56.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-25T16:47:16.000Z (about 7 years ago)
- Last Synced: 2024-07-05T00:56:43.747Z (4 months ago)
- Language: C#
- Size: 54.7 KB
- Stars: 17
- Watchers: 5
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-xamarin - ManageSleep ★15 - Manage auto sleep / auto lock in all platforms. This is useful when dealing with long running processes. (XPlat APIs)
README
Xam.Plugins.ManageSleep plugin for Xamarin
==========================================Manage auto sleep / auto lock in all platforms. This is useful when dealing with long running processes.
NuGet package is available here: https://www.nuget.org/packages/Xam.Plugins.ManageSleep/
### Usage
**Android requires `WAKE_LOCK` permission, see below.**This should fit most scenarios. Instanciate SleepMode and use one of its method:
```C#
///
/// Executes the given action without having the device going to sleep.
///
/// Action to execute.
void DoWithoutSleep(Action action);///
/// Awaits the given task without having the device going to sleep.
///
/// A task to await.
/// Task to run.
Task DoWithoutSleepAsync(Task action);
```Example:
```C#
var sleepMode = new SleepMode();
sleepMode.DoWithoutSleep(() => {
//long running operation...
});
```
### Android permissionsAndroid requires that the app manifest includes the `WAKE_LOCK` permission.
https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK
Include this permission via your IDE or including this XML:
```
```
### Advanced usage
If you need a fine-grained control of the auto sleep. Then you can use the following method:
```C#
///
/// Activates or desactivates the auto sleep mode. True to activate it (default), False to deactivate it.
/// Use with caution: if you deactivated auto sleep you will need to reactivate it.
/// DoWithoutSleep and DoWithoutSleepAsync methods are preferred since they automatically resume auto sleep.
///
/// If set to true activates auto sleep mode.
void ActivateAutoSleepMode(bool activateAutoSleepMode);
```Therefore be careful when using it: if you deactivated auto sleep then you should reactivate it. Furthermore it has to be done using the same instance of SleepMode.
If you use a framework like MvvmCross then it is easier: you will typically have one instance of SleepMode registered as a singleton for the ISleepMode interface.