Java Code Examples for android.content.Intent#ACTION_SCREEN_ON

The following examples show how to use android.content.Intent#ACTION_SCREEN_ON . These examples are extracted from open source projects. 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 Project: Simple-Lockscreen   File: LockScreenService.java    License: MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onCreate() {
    KeyguardManager.KeyguardLock key;
    KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

    //This is deprecated, but it is a simple way to disable the lockscreen in code
    key = km.newKeyguardLock("IN");

    key.disableKeyguard();

    //Start listening for the Screen On, Screen Off, and Boot completed actions
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);

    //Set up a receiver to listen for the Intents in this Service
    receiver = new LockScreenReceiver();
    registerReceiver(receiver, filter);

    super.onCreate();
}
 
Example 2
Source Project: talkback   File: ScreenMonitor.java    License: 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
@Override
protected void provide() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);

    filter.addAction(Intent.ACTION_SHUTDOWN);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);
    filter.addAction(Intent.ACTION_BATTERY_LOW);
    filter.addAction(Intent.ACTION_BATTERY_OKAY);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);

    mReceiver = new DeviceStateReceiver();
    getContext().registerReceiver(mReceiver, filter);
}
 
Example 4
@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 5
Source Project: FreezeYou   File: TriggerTasksService.java    License: 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
@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 7
/**
 * Called by {@link PowerManagerService} on system ready, *with no lock held*.
 */
public void systemReady() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
    filter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED);
    mContext.registerReceiver(mReceiver, filter);

    mFileUpdater.systemReady(LocalServices.getService(ActivityManagerInternal.class)
            .isRuntimeRestarted());
    mHandler.postSystemReady();
}
 
Example 8
Source Project: android_9.0.0_r45   File: Notifier.java    License: Apache License 2.0 5 votes vote down vote up
public Notifier(Looper looper, Context context, IBatteryStats batteryStats,
        SuspendBlocker suspendBlocker, WindowManagerPolicy policy) {
    mContext = context;
    mBatteryStats = batteryStats;
    mAppOps = mContext.getSystemService(AppOpsManager.class);
    mSuspendBlocker = suspendBlocker;
    mPolicy = policy;
    mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
    mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
    mInputMethodManagerInternal = LocalServices.getService(InputMethodManagerInternal.class);
    mStatusBarManagerInternal = LocalServices.getService(StatusBarManagerInternal.class);
    mTrustManager = mContext.getSystemService(TrustManager.class);
    mVibrator = mContext.getSystemService(Vibrator.class);

    mHandler = new NotifierHandler(looper);
    mScreenOnIntent = new Intent(Intent.ACTION_SCREEN_ON);
    mScreenOnIntent.addFlags(
            Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND
            | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
    mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
    mScreenOffIntent.addFlags(
            Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND
            | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
    mScreenBrightnessBoostIntent =
            new Intent(PowerManager.ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED);
    mScreenBrightnessBoostIntent.addFlags(
            Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);

    mSuspendWhenScreenOffDueToProximityConfig = context.getResources().getBoolean(
            com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);

    // Initialize interactive state for battery stats.
    try {
        mBatteryStats.noteInteractive(true);
    } catch (RemoteException ex) { }
}
 
Example 9
@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 10
Source Project: NetUpDown   File: NetTrafficService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;
    }
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_OFF:
            isSleep = true;
            break;
        case Intent.ACTION_SCREEN_ON:
            isSleep = false;
    }
}
 
Example 11
Source Project: YiBo   File: AutoUpdateService.java    License: 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 12
public static boolean register(Context context) {
	if (context != null) {
		IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
		try {
			context.getApplicationContext().registerReceiver(getInstance(), intentFilter);
			return true;
		} catch(IllegalArgumentException e) 
		{	// we are already registered
		}
	}
	return false;
}
 
Example 13
@Override
protected void onCreate(Bundle bundle) {
	super.onCreate(bundle);
	// INITIALIZE RECEIVER
	IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
	filter.addAction(Intent.ACTION_SCREEN_OFF);
	BroadcastReceiver mReceiver = new SleepReceiver();
	registerReceiver(mReceiver, filter);
}
 
Example 14
@Override
public void onCreate() {
	super.onCreate();
	Log.d("BatteryFu", "Screen service started");
	
       // register receiver that handles screen on and screen off logic
       IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
       filter.addAction(Intent.ACTION_SCREEN_OFF);
       filter.addAction(Intent.ACTION_USER_PRESENT);
       generalReceiver = new GeneralReceiver();
       setScreenOn(getApplicationContext(), true);
       registerReceiver(generalReceiver, filter);		
}
 
Example 15
private void registerReceiver() {
    unregisterReceiver();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    mReceiver = new ScreenReceiver();
    registerReceiver(mReceiver, filter);
    isRegistered = true;
}
 
Example 16
@Override
public void onReceive(Context context, Intent intent) {
    switch (Objects.requireNonNull(intent.getAction())) {
        case Intent.ACTION_SCREEN_ON:
            if (DEBUG) Log.v(TAG, "ACTION_SCREEN_ON intent received");
            if (mHyperionEncoder != null && !isCapturing()) {
                if (DEBUG) Log.v(TAG, "Encoder not grabbing, attempting to restart");
                mHyperionEncoder.resumeRecording();
            }
            notifyActivity();
        break;
        case Intent.ACTION_SCREEN_OFF:
            if (DEBUG) Log.v(TAG, "ACTION_SCREEN_OFF intent received");
            if (mHyperionEncoder != null) {
                if (DEBUG) Log.v(TAG, "Clearing current light data");
                mHyperionEncoder.clearLights();
            }
        break;
        case Intent.ACTION_CONFIGURATION_CHANGED:
            if (DEBUG) Log.v(TAG, "ACTION_CONFIGURATION_CHANGED intent received");
            if (mHyperionEncoder != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (DEBUG) Log.v(TAG, "Configuration changed, checking orientation");
                mHyperionEncoder.setOrientation(getResources().getConfiguration().orientation);
            }
        break;
        case Intent.ACTION_SHUTDOWN:
        case Intent.ACTION_REBOOT:
            if (DEBUG) Log.v(TAG, "ACTION_SHUTDOWN|ACTION_REBOOT intent received");
            stopScreenRecord();
        break;
    }
}
 
Example 17
@Override
public void onCreate() {
    super.onCreate();
    running = true;
    MainActivity guiCopy = gui;
    if (guiCopy != null) {
        guiCopy.updateCheckbox();
    }

    Log.d(LOG, "Service started"); //NON-NLS
    Cfg.Init(this);

    if (Cfg.UseLightSensor) {
        sensors = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensors.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            StartSensor.get().registerListener(sensors, this, lightSensor, 1200000, 1000000);
        }

        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        screenOffReceiver = new ScreenOffReceiver();
        registerReceiver(screenOffReceiver, filter);
    } else {
        startFilter();
    }
    Cfg.WasEnabled = true;
    Cfg.Save(this);
}
 
Example 18
/**
 * 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 19
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
	filter.addAction(Intent.ACTION_SCREEN_OFF);
	PowerDownReceiver receiver = new PowerDownReceiver();
	registerReceiver(receiver, filter);
}
 
Example 20
@Override
public void onReceive(Context context, Intent intent) {
    String event = null;
    String type = null;

    switch(intent.getAction()){
        case Intent.ACTION_SCREEN_OFF:
            event = DeviceEvent.EVENT_SCREEN_OFF;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_SCREEN_ON:
            event = DeviceEvent.EVENT_SCREEN_ON;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_USER_PRESENT:
            event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_BOOT_COMPLETED:
            event = DeviceEvent.EVENT_BOOT_COMPLETED;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_SHUTDOWN:
            event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_BATTERY_LOW:
            event = DeviceEvent.EVENT_BATTERY_LOW;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_BATTERY_OKAY:
            event = DeviceEvent.EVENT_BATTERY_OKAY;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_CONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_DISCONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case AudioManager.RINGER_MODE_CHANGED_ACTION:
            AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
            switch (am.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    event = DeviceEvent.EVENT_RINGER_SILENT;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_VIBRATE:
                    event = DeviceEvent.EVENT_RINGER_VIBRATE;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_NORMAL:
                    event = DeviceEvent.EVENT_RINGER_NORMAL;
                    type = DeviceEvent.TYPE_RINGER;
                    break;
            }
        default:
            break;
    }

    if (type != null)
        output(new DeviceEvent(type, event));
}