๐Ÿš€ 8.9 Released! โ†’ โšก๏ธ New Node-API Engine Preview, ๐Ÿ“ฒ ns widget ios, ๐Ÿ’… Tailwind v4 and more...
Read Announcement

View on GitHub

@nativescript/brightness โ€‹

A plugin that get and set the device's brightness level.

Contents โ€‹

Installation โ€‹

cli
npm install @nativescript/brightness

Required permissions for Android โ€‹

Add the following permission to the App_Resources/src/main/AndroidManifest.xml file:

  • <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="es.amplya.app_inventario">

	<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

	<application android:name="com.tns.NativeScriptApplication">
	...

Use @nativescript/brightness โ€‹

Set the device brightness level โ€‹

To set the device's brightness level, call the set() method on an instance of the Brightness class, passing it the BrightnessOptions object with the desired intensity value.

typescript
import { Brightness } from '@nativescript/brightness'
const brightness = new Brightness()

brightness.set({
  intensity: 25,
})

Get the device brightness level โ€‹

To get the device's brightness level, call the get() method on an instance of the Brightness class.

ts
bightnessLevel: number = brightness.get()

API โ€‹

Brightness class โ€‹

MethodReturnsDescription
set(options: BrightnessOptions)voidSets screen's brightness level to the desired intensity
get()numberReturns current screen brightness value as a number between 0 and 100
getNative() numberReturns current native screen brightness value.
iOS: a value between 0.0 and 1.0.
Android: 0 and 255

BrightnessOptions interface โ€‹

PropertyDefaultDescription
intensity100Defines the desired brightness value, which should be a number between 0 and 100.

License โ€‹

Apache License Version 2.0