Just - Screen Always On

ScreenOn

Toggles the screen to always be on or not always on.

:memo: Specifications


:date: Created: 2025-05-09T23:00:00Z
:floppy_disk: Size: 4.10 KB
:gear: Version: 1.0
:iphone: Minimum API Level: 7
:date: Latest Update: 2025-05-09T23:00:00Z
:computer: Built & documented using: FAST v3.1.0

Blocks:

ScreenAlwaysOn

sets the existing window to always on or not always on, use true or false blocks

component_method

Parameter Type
status boolean

IsScreenAlwaysOn

status of ScreenAlwaysOn

component_set_get

  • Return type: boolean

Example Usage:

image

AIX

uk.co.metricrat.screenonV1.aix

Source
package uk.co.metricrat.screenon;

//ref: https://developer.android.com/develop/background-work/background-tasks/awake/screen-on

import android.app.*;
import android.view.*;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

@DesignerComponent(
	version = 1,
	versionName = "1.0",
	description = "Toggles the screen to always be on or not always on. Developed by TIMAI2, built using Fast.",
	iconName = "icon.png"
)
public class ScreenOn extends AndroidNonvisibleComponent {

    private ComponentContainer container;
    private final Activity activity;
    private boolean sao = false;

  public ScreenOn(ComponentContainer container) {

      super(container.$form());
      this.container = container;
      this.activity = container.$context();
  }

  @SimpleFunction(description = "sets the existing window to always on or not always on, use true or false blocks")
  public void ScreenAlwaysOn(boolean status) {

      sao = status;

      if (status) {
          this.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      } else {
          this.activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      }
  }

  @SimpleProperty(description="status of ScreenAlwaysOn")
    public boolean IsScreenAlwaysOn() {
      return sao;
  }
}

Enjoy :smiley: , and all feedback and comments welcome.

Available for use in any MIT AppInventor projects or competitions

#####################################################################
This work by TIMAI2 is licensed under a
Creative Commons Attribution-ShareAlike 4.0 Unported License with attribution.
Please use name = TIMAI2 and link to this source page when giving credit.
#####################################################################

4 Likes