2.0.0 (Mar 17, 2018)
May 29, 2017
Dec 7, 2023
Nishant Srivastava (nisrulz)
Nishant Srivastava (nisrulz)
Source code



Android library handling flashlight for camera and camera2 api. Added support for handling display/screen light.

Built with ❤︎ by Nishant Srivastava and contributors

Including in your project

Lantern is available in the Jcenter, so getting it as simple as adding it as a dependency

implementation "com.github.nisrulz:lantern:{latest version}"

where {latest version} corresponds to published version in


Lantern uses a fluent api. You can enable/disable feature by calling the right method on the Lantern object. Use what you need!

  1. Declare permissions in your app's AndroidManifest.xml file

    <!-- Permissions : Allows access to flashlight -->
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <!-- Permissions : Allows access to change system settings for handling screen states -->
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
  2. Init code.

    private Lantern lantern = new Lantern(this)
                                // Check and request for system permission, used for handling screen states
                                // OPTIONAL: Setup Lantern to observe the lifecycle of the activity/fragment, handles auto-calling cleanup() method
    // Init Lantern's torch feature by calling `initTorch()`, which also check if camera permission is granted + camera feature exists
    // In case permission is not granted, request for the permission and retry by calling `initTorch()` method
    // NOTE: In case camera feature/hardware does not exist, `initTorch()` will return `false` and Lantern will not have
    // torch functionality but only screen based features
    if (!lantern.initTorch()) {
        // Request camera permission if it is not granted
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CODE);
    // Handle the runtime permission
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_CODE) {
            // Retry initializing the Lantern's torch feature
            if (!lantern.initTorch()) {
                // Camera Permission Denied! Do something.
  3. Cleanup

    If you are not observing the lifecyle of the activity/fragment via observeLifecycle(this) method, then you need to call cleanup() method in onDestroy() of the Activity.

    protected void onDestroy() {
  4. Manage states via

    • Turn On

          // Enable always on display
          // Set screen to full bright
          // Or set screen to Auto Bright
          // Enable torch via flash
          // Enable pulsating torch
          // Set the delay for between each pulse
          .withDelay(1, TimeUnit.SECONDS);
    • Turn Off

          // Disable always on display
          // Unset full bright screen state
          // Or unset screen from Auto Bright
          // Disable torch via flash
          // Disable pulsating torch

Pull Requests

I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:

  1. Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (Reformat code) on Mac (not sure for Windows) with Android Studio defaults. This project uses a modified version of Grandcentrix's code style, so please use the same when editing this project.
  2. If its a feature, bugfix, or anything please only change code to what you specify.
  3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
  4. Pull requests must be made against develop branch. Any other branch (unless specified by the maintainers) will get rejected.
  5. Check for existing issues first, before filing an issue.
  6. Have fun!


Licensed under the Apache License, Version 2.0, click here for the full license.

Author & support

This project was created by Nishant Srivastava but hopefully developed and maintained by many others. See the the list of contributors here.

If you appreciate my work, consider buying me a cup of ☕ to keep me recharged ????

  • PayPal
  • Bitcoin Address: 13PjuJcfVW2Ad81fawqwLtku4bZLv1AxCL

Donation to the project is always welcome which helps to maintain and keep my open source projects up to date!