A minimal Android application (targeting Android 16 / API 36) that locks the device screen with a single tap on its launcher icon.
The app uses Android's Accessibility Services API.
When the service is enabled, tapping the app icon calls
AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN — the screen locks instantly with no visible UI.
- Install the APK.
- Tap the Lock Screen icon.
- A dialog will appear — tap Open Settings.
- In Settings → Accessibility, find Lock Screen and toggle it on.
- Return to the home screen. Tapping the icon now locks the screen immediately.
| Item | Value |
|---|---|
| Minimum Android version | Android 9 (API 28) |
| Target Android version | Android 16 (API 36) |
| Required setup | Enable the included Accessibility Service once |
Why Accessibility?
Since Android 9 (API 28), only Device Policy / accessibility services can lock the screen programmatically. This app uses the least-privileged path: no device-admin enrollment, no additional permissions beyondBIND_ACCESSIBILITY_SERVICE(which is granted automatically to the declared service).
- Android Studio (Ladybug 2024.2 or newer) or Gradle 8.9 + JDK 17
- Android SDK platform 36
./gradlew assembleDebug./gradlew assembleReleaseThe release APK will be in app/build/outputs/apk/release/.
app/src/main/
├── AndroidManifest.xml – permissions & component declarations
├── java/com/lockscreen/app/
│ ├── LockActivity.kt – transparent launcher Activity
│ └── LockScreenService.kt – AccessibilityService that locks the screen
└── res/
├── drawable/
│ ├── ic_launcher_background.xml – icon background (blue)
│ └── ic_launcher_foreground.xml – icon foreground (white padlock)
├── mipmap-anydpi-v26/
│ └── ic_launcher.xml – adaptive launcher icon
├── values/
│ ├── strings.xml – all user-visible strings
│ └── themes.xml – transparent Activity theme
└── xml/
└── accessibility_service_config.xml – service metadata
The accessibility service sets android:accessibilityEventTypes="0", meaning it does not
read, observe, or intercept any accessibility events on the device. It only performs a
single global action (lock screen) when explicitly triggered by the launcher Activity.