Fakebear
Fakebear

Reputation: 449

Which API can get the display brightness?

I found:

BrightnessOverride bo = BrightnessOverride.GetDefaultForSystem();
bo.BrightnessLevel();

may related to brightness read. But when I run the code, it got an exception says: "Access denied". The API document say it need a systemManagement capability. I tried create a Package.appxmanifest file and write below code in it. But the visual studio warn that systemManagement is not permitted argument for it.

Anyone knows why? Or other advice to fetch display brightness? thanks.

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
  <Identity Name=""
            Version=""
            Publisher="" />
  <Properties>
    <DisplayName></DisplayName>
    <PublisherDisplayName></PublisherDisplayName>
    <Logo></Logo>
  </Properties>
  <Prerequisites>
    <OSMinVersion></OSMinVersion>
    <OSMaxVersionTested></OSMaxVersionTested>
  </Prerequisites>
  <Resources>
    <Resource Language="" />
  </Resources>
  <Capabilities>
    <Capability Name="systemManagement"/>
  </Capabilities>
  <Applications>
    <Application Id="" StartPage="">
      <VisualElements DisplayName="" Description=""
           Logo="" SmallLogo=""
           ForegroundText="" BackgroundColor="">
        <SplashScreen Image="" />
      </VisualElements>
    </Application>
  </Applications>
</Package>

Upvotes: 2

Views: 901

Answers (1)

kennyzx
kennyzx

Reputation: 12993

It is the user, instead of the app, can adjust the brightness of the display. Auto-adjust brightness is a task of the system. Oh, although not a strong reason, remember that UWP can run on devices without a display.

So UWP does not provide this functionality (getting current brightness reading of the display).

As to why BrightnessOverride requires systemManagement capability, I don't quite understand. After all, this overriding is per-application, means only the app itself is affected.

Edit:

As Raymond pointed out in his comment, this API can control per-application brightness as well as system brightness.

Setting display brightness is basic system administration, so it needs the capability to be declared.

Upvotes: 2

Related Questions