Flashlight extension

Overview

The Flashlight Extension allows you to control the device's flashlight without needing camera permission. This extension provides two simple functions to turn the flashlight on and off.

Installation

  1. Download the .aix file of the Flashlight extension.
    com.damiano.flashlight.aix (4.1 KB)

  2. Open your MIT App Inventor project.

  3. Click on Extensions in the left-side menu.

  4. Choose Import extension and select From my computer.

  5. Upload the .aix file and click OK.

Components

This extension is a non-visible component and does not appear on the user interface.

Available Methods

1. TurnOnFlash

component_method (5)

  • Description: Turns the device's flashlight on.
  • Usage:
Flashlight.TurnOnFlash()
  • Example:
    Use this block when a button is clicked to turn on the flashlight:
    • When Button1.Click:
      • Call Flashlight.TurnOnFlash

2. TurnOffFlash

component_method (6)

  • Description: Turns the device's flashlight off.
  • Usage:
Flashlight.TurnOffFlash()
  • Example:
    Use this block when a button is clicked to turn off the flashlight:
    • When Button2.Click:
      • Call Flashlight.TurnOffFlash

Example Usage

ASd.aia (6.0 KB)

Here’s how to use the Flashlight extension in your MIT App Inventor project:

  1. Add the Flashlight Extension to your project.
  2. Drag and Drop two buttons (Button1 and Button2) onto the designer screen.
  3. Configure the Blocks:
  • Button1: When clicked, should turn on the flashlight using Flashlight.TurnOnFlash().
  • Button2: When clicked, should turn off the flashlight using Flashlight.TurnOffFlash().

Screenshot of Blocks Example

Create a simple app with two buttons to turn the flashlight on and off.

  • Button1 (Turn On):
when Button1.Click
do
  call Flashlight.TurnOnFlash
  • Button2 (Turn Off):
when Button2.Click
do
  call Flashlight.TurnOffFlash

Notes

  • Permission: This extension does not require camera permission (android.permission.CAMERA), which makes it easier to use in applications where privacy concerns are an issue.
  • Compatibility: Ensure that the device supports flashlight operations and that it is running a version of Android compatible with the Camera2 API.

Changelog

  • Version 1.0:
    • Initial release with basic functionality to turn the flashlight on and off.
  • Open Source Code:
    flashlight.zip.aia (11.4 KB)

Fully made by ChatGPT

3 Likes