Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jamesmontemagno/BatteryPlugin
Battery Plugin for Xamarin and Windows
https://github.com/jamesmontemagno/BatteryPlugin
Last synced: 30 days ago
JSON representation
Battery Plugin for Xamarin and Windows
- Host: GitHub
- URL: https://github.com/jamesmontemagno/BatteryPlugin
- Owner: jamesmontemagno
- License: mit
- Archived: true
- Created: 2016-06-02T23:13:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-03T20:37:54.000Z (over 1 year ago)
- Last Synced: 2024-10-06T19:08:22.094Z (2 months ago)
- Language: C#
- Size: 521 KB
- Stars: 27
- Watchers: 8
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-xamarin-forms - Battery Status ★28
README
## Battery Status Plugin for Xamarin and Windows
Simple cross platform plugin to check battery status of mobile device, get remaining percentage for Xamarin.iOS, Xamarin.Android, Windows, and Xamarin.Forms projects.
### Setup
* Available on NuGet: http://www.nuget.org/packages/Xam.Plugin.Battery [![NuGet](https://img.shields.io/nuget/v/Xam.Plugin.Battery.svg?label=NuGet)](https://www.nuget.org/packages/Xam.Plugin.Battery/)
* Install into your PCL/NetStanadrd project and Client projects.Build Status:
* ![Build status](https://jamesmontemagno.visualstudio.com/_apis/public/build/definitions/6b79a378-ddd6-4e31-98ac-a12fcd68644c/12/badge)
* CI NuGet Feed: http://myget.org/F/xamarin-plugins### Migrate to: [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/index?WT.mc_id=friends-0000-jamont) or [.NET MAUI](https://learn.microsoft.com/dotnet/maui/platform-integration/?WT.mc_id=friends-0000-jamont)
I have been working on Plugins for Xamarin for a long time now. Through the years I have always wanted to create a single, optimized, and official package from the Xamarin team at Microsoft that could easily be consumed by any application. The time is now with [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/index?WT.mc_id=friends-0000-jamont), which offers over 50 cross-platform native APIs in a single optimized package. I worked on this new library with an amazing team of developers and I highly highly highly recommend you check it out.
Additionally, Xamarin.Essentials is now included in & [.NET MAUI](https://learn.microsoft.com/dotnet/maui/platform-integration/?WT.mc_id=friends-0000-jamont).
Due to the functionality being included "in the box" I have decided to officially archive this repo.
## Platform Support
|Platform|Version|
| ------------------- | :------------------: |
|Xamarin.iOS|iOS 6+|
|Xamarin.Android|API 10+|
|Windows 10 UWP|10+|
|Tizen.NET|4.0+|**Windows Store has a blank DLL that always returns 100, AC, and Full as there is no API for checking battery**
### API Usage
Call **CrossBattery.Current** from any project or PCL to gain access to APIs.
**RemainingChargePercent**
```csharp
///
/// Current battery level 0 - 100
///
int RemainingChargePercent { get; }
```**Status**
```csharp
///
/// Current status of the battery
///
BatteryStatus Status { get; }
```This returns an enum with the current status of the battery. If charging or not:
```csharp
///
/// Current status of battery
///
public enum BatteryStatus
{
///
/// Plugged in and charging
///
Charging,
///
/// Battery is being drained currently
///
Discharging,
///
/// Battery is full completely
///
Full,
///
/// Not charging, but not discharging either
///
NotCharging,
///
/// Unknown or other status
///
Unknown}
```Important:
* iOS: only returns Charging, Full, Discharging, and Unknown.**PowerSource**
```csharp
///
/// Currently how the battery is being charged.
///
PowerSource PowerSource { get; }
```Returns how the phone is being charged
#### Events
You can subscribe to BatteryChanged, which will return BatteryChangedEventArgs with all information you need.
This occurs when plugged, unplugged, or battery change.```csharp
///
/// Event handler when battery changes
///
event BatteryChangedEventHandler BatteryChanged;
```#### License
Under MIT, see LICENSE file.