uid |
---|
Uno.Features.WSPower |
[!TIP] This article covers Uno-specific information for the
Windows.System.Power
namespace. For a full description of the feature and instructions on using it, see Windows.System.Power Namespace.
Windows.System.Power.PowerManager
class to query the battery and charging status of the device and subscribe to the related events when these change.PowerManager
Legend
Picker | UWP/WinUI | WebAssembly | Android | iOS | macOS | Skia Desktop |
---|---|---|---|---|---|---|
BatteryStatus |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
EnergySaverStatus |
✔ | ✖ | ✔ | ✔ | ✖ ️ | ✖ |
PowerSupplyStatus |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
RemainingChargePercent |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
RemainingDischargeTime |
✔ | ✔ | ✖ | ✖ | ✖ ️ | ✖ |
BatteryStatusChanged |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
EnergySaverStatusChanged |
✔ | ✖ | ✔ | ✔ | ✖ ️ | ✖ |
PowerSupplyStatusChanged |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
RemainingChargePercentChanged |
✔ | ✔ | ✔ | ✔ | ✖ ️ | ✖ |
RemainingDischargeTimeChanged |
✔ | ✔ | ✖ | ✖ | ✖ ️ | ✖ |
For general usage, see PowerManager Class.
For Android, there is one permission you must configure before using this API in your project. To do that, add the following to AndroidManifest.xml
:
<uses-permission android:name="android.permission.BATTERY_STATS" />
RemainingChargePercentChanged
event is not updated continuously as there is no API that provides such events. It is triggered by system Low
and Ok
battery state broadcasts only. The RemainingChargePercent
property always returns the up-to-date value. For continuous monitoring you can set up periodic polling.
Before any of the properties/events of PowerManager
can be accessed, the class needs to be initialized via a platform-specific InitializeAsync
method:
#if HAS_UNO
var isAvailable = await PowerManager.InitializeAsync();
#endif
If the returned value is false
, refrain from using PowerManager
in your code, as it is not available in the browser the user is using.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )