Java Code Examples for android.content.Intent#ACTION_SCREEN_OFF

The following examples show how to use android.content.Intent#ACTION_SCREEN_OFF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyService.java    From EZScreenshot with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_OFF: {
            LogUtil.LOGI("screen off");
            tryTemporarilyPauseScreenshotService();
            break;
        }
        case Intent.ACTION_SCREEN_ON: {
            LogUtil.LOGI("screen on");
            tryTemporarilyResumeScreenshotService();

            break;
        }
    }
}
 
Example 2
Source File: ScreenMonitor.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  String action = intent.getAction();
  if (action == null) {
    return;
  }

  switch (action) {
    case Intent.ACTION_SCREEN_ON:
      isScreenOn = true;
      break;
    case Intent.ACTION_SCREEN_OFF:
      isScreenOn = false;
      if (screenStateListener != null) {
        screenStateListener.screenTurnedOff();
      }
      break;
    default: // fall out
  }
}
 
Example 3
Source File: MainActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action != null) {
        switch (action) {
            case Intent.ACTION_SCREEN_OFF:
                if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) {
                    context.startActivity(new Intent(context, LockScreenActivity.class));
                }
                break;
            case Intent.ACTION_SCREEN_ON:
                collapsePanel();
                recreate();
                break;
        }
    }
}
 
Example 4
Source File: ScreenLockListener.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action != null) {
        switch (action) {
            case Intent.ACTION_SCREEN_OFF:
                if (new AppPreferences(context).getBoolean("onekeyFreezeWhenLockScreen", false)) {
                    ServiceUtils.startService(context,
                            new Intent(context, OneKeyFreezeService.class)
                                    .putExtra("autoCheckAndLockScreen", false)
                    );
                }
                break;
            default:
                break;
        }
    }
}
 
Example 5
Source File: TriggerTasksService.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    final SQLiteDatabase db = context.openOrCreateDatabase("scheduledTriggerTasks", MODE_PRIVATE, null);
    db.execSQL(
            "create table if not exists tasks(_id integer primary key autoincrement,tg varchar,tgextra varchar,enabled integer(1),label varchar,task varchar,column1 varchar,column2 varchar)"
    );
    Cursor cursor = db.query("tasks", null, null, null, null, null, null);
    if (action != null && cursor.moveToFirst()) {
        switch (action) {
            case Intent.ACTION_SCREEN_OFF:
                onActionScreenOnOff(context, cursor, false);
                break;
            case Intent.ACTION_SCREEN_ON:
                onActionScreenOnOff(context, cursor, true);
                break;
            default:
                break;
        }
    }
    cursor.close();
    db.close();
}
 
Example 6
Source File: SensorsDumpService.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_ON:
            startListening();

            // Stop listening after some minutes to keep battery.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    synchronized (mEventList) {
                        stopListening();
                        mEventList.clear();
                    }
                }
            }, 120 * 1000);
            break;
        case Intent.ACTION_SCREEN_OFF:
            stopListening();
            dropToStorage();
            break;
    }
}
 
Example 7
Source File: AutoUpdateService.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();

	//启动网络监听;
	connChangeReceiver = new ConnectionChangeReceiver();
	IntentFilter connFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
	this.registerReceiver(connChangeReceiver, connFilter);

	updateNotifyReceiver = new AutoUpdateNotifyReceiver();
	IntentFilter updateNotifyFilter = new IntentFilter(Constants.ACTION_RECEIVER_AUTO_UPDATE_NOTIFY);
	this.registerReceiver(updateNotifyReceiver, updateNotifyFilter);

	updateReceiver = new AutoUpdateReceiver(accountList);
	IntentFilter updateFilter = new IntentFilter(Constants.ACTION_RECEIVER_AUTO_UPDATE);
	this.registerReceiver(updateReceiver, updateFilter);

	sheJiaoMao = (SheJiaoMaoApplication)this.getApplication();

	shakeUpdateListener = new ShakeUpdateListener(this);
	shakeUpdateListener.startMonitor();
	
	//锁屏和解屏的接收器
	screenOffReceiver = new ScreenOffReceiver();
	IntentFilter screenOffFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
	this.registerReceiver(screenOffReceiver, screenOffFilter);
	
	screenOnReceiver = new ScreenOnReceiver();
	IntentFilter screenOnFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
	this.registerReceiver(screenOnReceiver, screenOnFilter);
}
 
Example 8
Source File: BatterySaverController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG) {
        Slog.d(TAG, "onReceive: " + intent);
    }
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_ON:
        case Intent.ACTION_SCREEN_OFF:
            if (!isEnabled()) {
                updateBatterySavingStats();
                return; // No need to send it if not enabled.
            }
            // Don't send the broadcast, because we never did so in this case.
            mHandler.postStateChanged(/*sendBroadcast=*/ false,
                    REASON_INTERACTIVE_CHANGED);
            break;
        case Intent.ACTION_BATTERY_CHANGED:
            synchronized (mLock) {
                mIsPluggedIn = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
            }
            // Fall-through.
        case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED:
        case PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED:
            updateBatterySavingStats();
            break;
    }
}
 
Example 9
Source File: NotificationPopup.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.values[0] > 0) {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
        mSensorManager.unregisterListener(this);
        mProximity = null;
        mSensorManager = null;
    }
}
 
Example 10
Source File: AssistantService.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
public void registerReveicer() {
    registerReceiver(netWorkChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    IntentFilter inf = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    inf.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(scrennReceiver, inf);
    registerReceiver(headSetInReceiver, new IntentFilter("android.intent.action.HEADSET_PLUG"));
    IntentFilter bit = new IntentFilter(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
    // bit.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
    //bit.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
    registerReceiver(blueConnectStateBroadcastReceiver, bit);
    IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED_ACTION);
    smsFilter.setPriority(2147483647);
    smsFilter.addAction(GSM_SMS_RECEIVED_ACTION);
    registerReceiver(smsReceiver, smsFilter);
}
 
Example 11
Source File: NotificationPopup.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);

    setContentView(R.layout.vakit_notpopup);

    TextView name = findViewById(R.id.name);
    name.setText(getIntent().getStringExtra("name"));
    TextView vakit = findViewById(R.id.vakit);
    vakit.setText(getIntent().getStringExtra("vakit"));
    vakit.setKeepScreenOn(true);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (mProximity == null) {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
    } else {
        mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
    }
}
 
Example 12
Source File: VideoAccessibilityService.java    From WaterMonitor with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_OFF:
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "onReceive: Screen off");
            }
            setState(new IdleState(VideoAccessibilityService.this));
            break;
        default:
            break;
    }
}
 
Example 13
Source File: ScreenOnOffUpdateService.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
private void registerScreenListeners() {
    IntentFilter filterScreenOn = new IntentFilter(Intent.ACTION_SCREEN_ON);
    IntentFilter filterScreenOff = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    IntentFilter filterUserUnlocked = new IntentFilter(Intent.ACTION_USER_PRESENT);
    getApplication().registerReceiver(screenOnReceiver, filterScreenOn);
    getApplication().registerReceiver(screenOffReceiver, filterScreenOff);
    getApplication().registerReceiver(userUnlockedReceiver, filterUserUnlocked);
}
 
Example 14
Source File: NotificationPopup.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);

    setContentView(R.layout.vakit_notpopup);

    TextView name = findViewById(R.id.name);
    name.setText(getIntent().getStringExtra("name"));
    TextView vakit = findViewById(R.id.vakit);
    vakit.setText(getIntent().getStringExtra("vakit"));
    vakit.setKeepScreenOn(true);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    if (mProximity == null) {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
    } else {
        mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
    }
}
 
Example 15
Source File: KeyguardActivity.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers a receiver to finish activity when screen goes off and to
 * refresh window flags on screen on. You will need to
 * {@link #unregisterScreenEventsReceiver() unregister} it later.
 *
 * @see #unregisterScreenEventsReceiver()
 */
private void registerScreenEventsReceiver() {
    mScreenOffReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()) {
                case Intent.ACTION_SCREEN_ON:
                    if (mResumed) {
                        // Fake system ui visibility state change to
                        // update flags again.
                        mSystemUiListener.onSystemUiVisibilityChange(0);
                    }
                    break;
                case Intent.ACTION_SCREEN_OFF:
                    if (!KeyguardService.isActive) {
                        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                        pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Finalize the keyguard.").acquire(200);
                        KeyguardActivity.this.finish();
                    }
                    break;
            }
        }

    };

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); // max allowed priority
    registerReceiver(mScreenOffReceiver, intentFilter);
}
 
Example 16
Source File: BackgroundService.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	mReceiver = new DisplayReceiver();
	final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
	filter.addAction(Intent.ACTION_SCREEN_ON);
	registerReceiver(mReceiver, filter);
}
 
Example 17
Source File: ShadowsocksNotification.java    From Maying with Apache License 2.0 5 votes vote down vote up
private void initWithUpdateAction() {
    String action;
    if (Build.VERSION.SDK_INT < 20) {
        action = pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF;
    } else {
        action = pm.isInteractive() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF;
    }
    // upate
    update(action, true);
}
 
Example 18
Source File: ShadowsocksNotification.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
private void initWithUpdateAction() {
    String action;
    if (Build.VERSION.SDK_INT < 20) {
        action = pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF;
    } else {
        action = pm.isInteractive() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF;
    }
    // upate
    update(action, true);
}
 
Example 19
Source File: HdmiControlService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@ServiceThreadOnly
@Override
public void onReceive(Context context, Intent intent) {
    assertRunOnServiceThread();
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_OFF:
            if (isPowerOnOrTransient()) {
                onStandby(STANDBY_SCREEN_OFF);
            }
            break;
        case Intent.ACTION_SCREEN_ON:
            if (isPowerStandbyOrTransient()) {
                onWakeUp();
            }
            break;
        case Intent.ACTION_CONFIGURATION_CHANGED:
            String language = getMenuLanguage();
            if (!mLanguage.equals(language)) {
                onLanguageChanged(language);
            }
            break;
        case Intent.ACTION_SHUTDOWN:
            if (isPowerOnOrTransient()) {
                onStandby(STANDBY_SHUTDOWN);
            }
            break;
    }
}
 
Example 20
Source File: ScreenStateService.java    From secrecy with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mScreenStateReceiver = new ScreenStateReceiver();
    final IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mScreenStateReceiver, screenStateFilter);
}