Coder Social home page Coder Social logo

batteryplugin's Introduction

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

Build Status:

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, 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.

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

/// <summary>
/// Current battery level 0 - 100
/// </summary>
int RemainingChargePercent { get; }

Status

/// <summary>
/// Current status of the battery
/// </summary>
BatteryStatus Status { get; }

This returns an enum with the current status of the battery. If charging or not:

/// <summary>
/// Current status of battery
/// </summary>
public enum BatteryStatus
{
  /// <summary>
  /// Plugged in and charging
  /// </summary>
  Charging,
  /// <summary>
  /// Battery is being drained currently
  /// </summary>
  Discharging,
  /// <summary>
  /// Battery is full completely
  /// </summary>
  Full,
  /// <summary>
  /// Not charging, but not discharging either
  /// </summary>
  NotCharging,
  /// <summary>
  /// Unknown or other status
  /// </summary>
  Unknown

}

Important:

  • iOS: only returns Charging, Full, Discharging, and Unknown.

PowerSource

/// <summary>
/// Currently how the battery is being charged.
/// </summary>
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.

/// <summary>
/// Event handler when battery changes
/// </summary>
event BatteryChangedEventHandler BatteryChanged;

License

Under MIT, see LICENSE file.

batteryplugin's People

Contributors

jamesmontemagno avatar jongheonchoi avatar lucecarter avatar migueldeicaza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

batteryplugin's Issues

Continual 'Changed' events in droid even when no property is changed.

From a Visual Studio perspective... The BatteryChangedEventArgs e has no changed properties between events. Yet is being raised every quarter second or so. I'm going to have to filter this before actually throwing an event to the rest of my program. So...

  1. It would be nice if the plugin didn't hammer false change events.
  2. It would be nice if the 'equals' operator comparred values of the object instead of instance so we can see if two different event args are equal to each other.

Plugin can be used in VS 2017 - C#?

HI, I'd like to know if this plugin can be used in VisualStudio 2017, C#, >NET 4.6. for a Windows 10 desktop app. classic windows, not UWA.

Thanks,

[UWP] Always report 'Full' when is not

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 2.1.0
Device Tested On: Windows 10 (PC & Mobile)

Expected Behavior

Should not be Full if the percentage is less than 100% (Charging or discharging...)

Actual Behavior

Always reports Full, due to the wrong IF condition in line 92:

if (percentage >= 1.0)

it should be >=100, as percentage is 0-100

Return -1

Hi,
i'm using Xamarin to create UWP and Android App using your plugin and it's always return -1, in Emulator and local and on Raspberry Pi3

Bug

Version Number of Plugin: Version=2.1.1.0
Device Tested On: Raspberry Pi3
Simulator Tested On: Mobile Emulator 10.0.14393.0 1080p 6inch 2GB

Expected Behavior

to show 100 value

Actual Behavior

return -1

Steps to reproduce the Behavior

call from PCL

Feature Request:

is there something missing i didn't do?

Xamarin.Forms.Mac

Hi,

are you planning to add Forms.Mac Support as well?
Also asking for your other plugins

thanks for your awesome work

Helge

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.