androidmauibatterydevice-emulation

Implementation of Battery in Android Emulators Under Maui


Is there a setting or permission missing?

When we execute the code

if (Battery.Default.PowerSource == BatteryPowerSource.Battery)

the thread in which it is running vanishes and does not throw an exception.

The emulated device right at the moment is "Pixel 5 - API 33 (Android 13.0 - API 33)".


Solution

  • The issue was that

    BATTERYSTATS

    was not selected in

    SolutionExplorer > YourProjectName > Platforms > Android > AndroidManifest.xml

    The issue is that there was no permissions exception thrown.

    Also, the issue arises on attempts to access the battery from other than SolutionExplorer > YourProjectName > Platforms > Android > MainActivity.cs. This may be a bug.