Example usage for android.content Intent ACTION_SCREEN_OFF

List of usage examples for android.content Intent ACTION_SCREEN_OFF

Introduction

In this page you can find the example usage for android.content Intent ACTION_SCREEN_OFF.

Prototype

String ACTION_SCREEN_OFF

To view the source code for android.content Intent ACTION_SCREEN_OFF.

Click Source Link

Document

Broadcast Action: Sent when the device goes to sleep and becomes non-interactive.

Usage

From source file:g7.bluesky.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    // For handling managed profiles
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
    if (ENABLE_DEBUG_INTENTS) {
        filter.addAction(DebugIntents.DELETE_DATABASE);
        filter.addAction(DebugIntents.MIGRATE_DATABASE);
    }/*w  ww .  j  a  va 2 s.  c  o m*/
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    setupTransparentSystemBarsForLmp();
    mAttached = true;
    mVisible = true;
}

From source file:com.android.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    mAttached = true;/*from w  ww.  jav a 2  s .  c  om*/
    mVisible = true;

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onAttachedToWindow();
    }
}

From source file:com.example.sensingapp.SensingApp.java

/** Called when the activity is first created. */
@Override/*w w  w .j  a v  a 2 s.  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    int i;
    Location location = null;

    super.onCreate(savedInstanceState);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    try {
        Class.forName("android.os.AsyncTask");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    m_smSurScan = (SensorManager) getSystemService(SENSOR_SERVICE);

    PackageManager pm = getPackageManager();
    m_riHome = pm.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    m_nBufferSize = AudioRecord.getMinBufferSize(m_nAudioSampleRate, AudioFormat.CHANNEL_IN_STEREO,
            AudioFormat.ENCODING_PCM_16BIT);

    m_tmCellular = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    checkSensorAvailability();

    //Get Existing Project Name and Existing User Name
    preconfigSetting();

    /* When the power button is pressed and the screen goes off, the sensors will stop work by default,
     * Here keep the CPU on to keep sensor alive and also use SCREEN_OFF notification to re-enable GPS/WiFi
     */
    PowerManager pwrManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    m_wakeLock = pwrManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);

    registerReceiver(m_ScreenOffReceiver, filter);

    show_screen1();
}