What is the use of android.permission.FLASHLIGHT?

Partha Roy picture Partha Roy · Jan 31, 2018 · Viewed 7.6k times · Source

I'm developing a flashlight app using Camera 2 API. Every thing works fine.

While developing the app I came across quite a few tutorials and even posts from stack-overflow where people have used "android.permission.FLASHLIGHT" permission.

I tried to search official documentation for "android.permission.FLASHLIGHT" (in developer.android.com) but couldn't find any.

I just what to know what is permission is and is it required for turning torch mode on. If yes, why there is no official documentation and why is my app(targets API >=21) working without this permission?

Note: I tested my app in android 5, 6, 7, 8 and it works fine, except in Nokia 6 and Xiaomi redimi note.

Answer

Arda Çebi picture Arda Çebi · Feb 1, 2018

The <uses-permission android:name="android.permission.CAMERA" /> already has the option to use the flashlight.

But <uses-permission android:name="android.permission.FLASHLIGHT" /> only allows the user to use the flashlight without activating the camera hardware.

This means:

  • Use <uses-permission android:name="android.permission.CAMERA" /> if you want to develop an app that uses camera and flashlight.
  • Use <uses-permission android:name="android.permission.FLASHLIGHT" /> if you want to develop an app that ONLY uses flashlight.

But, some users have seen crashes using the <uses-permission android:name="android.permission.FLASHLIGHT" /> permission in their apps. So, you can use both of them to make sure your app is working without crashes (For example: Which permissions are required for Flashlight?)