Maximize/Minimize Screen Brightness in Android Java
2 min readMar 26, 2024
In Android, you can programmatically adjust the screen brightness to either maximize or minimize its intensity. This functionality can be particularly useful in applications where you want to provide users with control over their device’s display brightness.
- Manifest.xml add permissions
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
2. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="30dp"
tools:context=".MainActivity">
<Button
android:id="@+id/turn_off_screen_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Turn Off Screen"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/turn_on_screen_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/turn_off_screen_button"
android:layout_centerHorizontal="true"
android:text="Turn On Screen"
tools:ignore="MissingConstraints" />
</LinearLayout>