Example usage for android.content Intent ACTION_SCREEN_ON

List of usage examples for android.content Intent ACTION_SCREEN_ON

Introduction

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

Prototype

String ACTION_SCREEN_ON

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

Click Source Link

Document

Broadcast Action: Sent when the device wakes up and becomes interactive.

Usage

From source file:com.googlecode.eyesfree.brailleback.FocusTracker.java

public void register() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    mAccessibilityService.registerReceiver(this, filter);
}

From source file:com.googlecode.eyesfree.brailleback.FocusTracker.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_SCREEN_ON.equals(action) && mDisplayConnected) {
        setFocusFromInput();//from www .  ja  v  a2 s .  co m
    }
}

From source file:com.apexlabs.alarm.AlarmService.java

@Override
public void onCreate() {
    Log.d(TAG, "onCreate");

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    editor = prefs.edit();// www  .j  a va2s  .co m

    filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    mReceiver = new ScreenReceiver();
    registerReceiver(mReceiver, filter);

    listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            Log.d(TAG, "Shared Preferences Change Listener");
            if (key.equals(screenOnKey)) {
                boolean b = prefs.getBoolean(screenOnKey, false);
                if (b) {
                    Log.d(TAG, "Screen is On!");
                    handler.removeCallbacks(r);
                    handler.postDelayed(r, 1);
                } else {
                    Log.d(TAG, "Screen is Off!");
                    clearNotification(867);
                    handler.removeCallbacks(r);
                }
            }
        }
    };

    prefs.registerOnSharedPreferenceChangeListener(listener);
}

From source file:com.golden.android.eyecare.ForegroundService.java

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

    context = getApplicationContext();//from  w w  w  . ja  v a2 s  .c  om
    global = (Global) getApplicationContext();

    final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    final BroadcastReceiver screenoffReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                Log.v("screenoffReceiver", "SCREEN OFF");
                onDestroy();
                stopForeground(Boolean.TRUE);
            }
            return;
        }
    };
    registerReceiver(screenoffReceiver, filter);

}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    //   Log.e(this.getClass().getSimpleName(), "onReceive(): " + action);

    updateWifiViews = true;//from   w w w.  jav  a 2  s  .c om

    wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiState = wifiManager.getWifiState();
    wifiInfo = wifiManager.getConnectionInfo();

    if ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() == 0))
        detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());

    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        if (isConnectionReady(intent)) {
            String securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID());
            NetworkStateService.setWifiSecurityString(securityString);
            detailsString = context.getString(R.string.security) + ": " + securityString;

            Intent serviceIntent = new Intent(context, NetworkStateService.class);
            serviceIntent.setAction(Constants.ACTION_WIFI_CONNECTED);
            context.startService(serviceIntent);
        }

        partiallyUpdateWidgets(context);
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
            || Constants.ACTION_WIFI_SCANNING.equals(action)) {
        partiallyUpdateWidgets(context);
    } else if (Intent.ACTION_SCREEN_ON.equals(action) || Constants.ACTION_WIFI_LINK_SPEED.equals(action)) {
        if (isConnected()) {
            setDetailsString(context);
            partiallyUpdateWidgets(context);
        }
    } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) {
        if (isConnected())
            setDetailsString(context);

        partiallyUpdateWidget(context, AppWidgetManager.getInstance(context),
                intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    }
}

From source file:it.gmariotti.android.apps.dashclock.extensions.battery.BatteryExtension.java

@Override
protected void onInitialize(boolean isReconnect) {
    super.onInitialize(isReconnect);

    readPreferences();//w ww.j  a v  a  2s.co m

    if (onClickReceiver != null) {
        try {
            unregisterReceiver(onClickReceiver);
        } catch (Exception e) {
        }
    }

    IntentFilter intentFilter = new IntentFilter(REFRESH_INTENT_FILTER);
    onClickReceiver = new OnClickReceiver();
    registerReceiver(onClickReceiver, intentFilter);

    IntentFilter filterScreen = new IntentFilter();
    filterScreen.addAction(Intent.ACTION_SCREEN_ON);

    getApplicationContext().registerReceiver(mScreenOnReceiver, filterScreen);

    //scheduleRefresh(0);
}

From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    //   Log.e(this.getClass().getSimpleName(), "onReceive(): " + action);

    updateMobileDataViews = true;//from w ww  .ja va 2  s .  c o m

    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    dataState = telephonyManager.getDataState();
    isMobileDataEnabled = MobileDataUtils.isMobileDataEnabled(context);
    isAirplaneModeOn = MobileDataUtils.isAirplaneModeOn(context);
    isMobileOutOfService = NetworkStateService.isMobileOutOfService();
    isDataRoaming = isDataRoaming(context);
    networkOperatorAndServiceProvider = getNetworkOperatorAndServiceProvider(context);
    dataUsageBytes = NetworkStateService
            .setGetDataUsageBytes(TrafficStats.getMobileRxBytes() + TrafficStats.getMobileTxBytes());

    if (Constants.ACTION_DATA_CONNECTION_CHANGED.equals(action)
            || Constants.ACTION_DATA_STATE_CHANGED.equals(action)
            || Constants.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
        // Needed to get around a known bug in Android 5.x: https://code.google.com/p/android/issues/detail?id=78924
        if ((dataState == TelephonyManager.DATA_CONNECTED) && (dataUsageBytes == 0)
                && !NetworkStateService.isWaitingForDataUsage()) {
            NetworkStateService.setWaitingForDataUsage(true);
            Intent serviceIntent = new Intent(context, NetworkStateService.class);
            serviceIntent.setAction(Constants.ACTION_DATA_CONNECTED);
            context.startService(serviceIntent);
        }

        partiallyUpdateWidgets(context);
    } else if (Constants.ACTION_DATA_USAGE_UPDATE.equals(action) || Intent.ACTION_SCREEN_ON.equals(action)) {
        partiallyUpdateWidgets(context);
    } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) {
        partiallyUpdateWidget(context, AppWidgetManager.getInstance(context),
                intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    }
}

From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate()");
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    mBroadcastReceiver = new BroadcastReceiver() {

        @Override// w  w  w . jav a2  s  . c  om
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive(): " + intent.getAction());
        }
    };

    registerReceiver(mBroadcastReceiver, filter);

    readPersistedData();
    mCastManager = VideoChromeCastManager.initialize(this, mApplicationId, mTargetActivity, null);
    if (!mCastManager.isConnected()) {
        mCastManager.reconnectSessionIfPossible(this, false);
    }
    mConsumer = new VideoCastConsumerImpl() {
        @Override
        public void onApplicationDisconnected(int errorCode) {
            Log.d(TAG, "onApplicationDisconnected() was reached");
            stopSelf();
        }

        @Override
        public void onRemoteMediaPlayerStatusUpdated() {
            int mediaStatus = mCastManager.getPlaybackStatus();
            VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus);
        }

    };
    mCastManager.addVideoCastConsumer(mConsumer);
}

From source file:org.durka.hallmonitor.CoreReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(QUICKBOOT_POWERON)
            || intent.getAction().equals(HTC_QUICKBOOT_POWERON)) {
        Log.d(LOG_TAG + ".boot", "Boot called.");
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (prefs.getBoolean("pref_enabled", false)) {
            Intent mIntent = new Intent(context, CoreService.class);
            context.startService(mIntent);
        }/*from ww  w. j  ava  2 s. c o  m*/
    }

    if (CoreStateManager.getInitialized()) {
        localContext = CoreStateManager.getContext();
        mStateManager = ((CoreApp) localContext).getStateManager();
    } else {
        return;
    }

    if (!mStateManager.getPreference().getBoolean("pref_enabled", false)) {
        return;
    }

    mStateManager.acquireCPUGlobal();

    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {

        Log.d(LOG_TAG + ".screen", "Screen on event received.");

        if (mStateManager.getCoverClosed()) {
            Log.d(LOG_TAG + ".screen", "Cover is closed, display Default Activity.");
            mStateManager.setBlackScreenTime(0);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else {
            // Log.d(LOG_TAG + ".screen",
            // "Cover is open, free everything.");
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
        }

    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        Log.d(LOG_TAG + ".screen", "Screen off event received.");
        // mStateManager.freeDevice();

    } else if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(ALARM_ALERT_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm on event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {

            Log.d(LOG_TAG + ".alarm", "Alarm controls are enabled, taking action.");
            mStateManager.setAlarmFiring(true);

            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_ALARM);
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".alarm", "Alarm controls are not enabled.");
        }

    } else if (intent.getAction().equals(ALARM_DONE_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm done event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {
            Log.d(mStateManager.getPreference() + ".alarm", "alarm is over, cleaning up");
            mStateManager.setAlarmFiring(false);

            if (mStateManager.getCoverClosed()) {
                Intent mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                mStateManager.sendToCoreService(mIntent);
            }
        }
    } else if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {

        if (mStateManager.getPreference().getBoolean("pref_phone_controls", false)) {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            Log.d(LOG_TAG + ".phone", "phone state changed to " + state);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(true);
                mStateManager.setCallFrom(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));
                Log.d(LOG_TAG, "call from " + mStateManager.getCallFrom());
                mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_CALL);
                mStateManager.sendToCoreService(mIntent);
            } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(false);
                Log.d(LOG_TAG, "call is over, cleaning up");
                if (mStateManager.getCoverClosed()) {
                    mIntent = new Intent(localContext, CoreService.class);
                    mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                    mStateManager.sendToCoreService(mIntent);
                }
            } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            }
        } else {
            Log.d(LOG_TAG + ".phone", "phone controls are not enabled");
        }
    } else if (intent.getAction().equals(mStateManager.getActionCover())) {
        int state = intent.getIntExtra(EXTRA_LID_STATE, LID_ABSENT);
        Log.d(LOG_TAG + ".cover", "cover state changed to " + state);
        if (state == LID_CLOSED) {
            Log.d(LOG_TAG + ".cover", "Cover is close, enable Default Activity.");
            mStateManager.setCoverClosed(true);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else if (state == LID_OPEN) {
            // Log.d(LOG_TAG + ".cover",
            // "Cover is open, stopping Default Activity.");
            mStateManager.setCoverClosed(false);
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
            mStateManager.sendToCoreService(mIntent);
        }

    } else if (intent.getAction().equals(TORCH_STATE_CHANGED)) {
        if (mStateManager.getPreference().getBoolean("pref_flash_controls", false)) {
            Log.d(LOG_TAG + ".torch", "torch state changed");
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_TORCH_STATE);
            if (intent.getIntExtra("state", 0) != 0) {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, true);
            } else {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, false);
            }
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".torch", "torch controls are not enabled.");
        }

    } else if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getExtras().getInt("state");
        Log.d(LOG_TAG + ".headset", "headset is " + (state == 0 ? "gone" : "here") + "!");
        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_HEADSET_PLUG);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals("org.durka.hallmonitor.debug")) {
        Log.d(LOG_TAG + "", "received debug intent");
        // test intent to show/hide a notification
        boolean showhide = false;
        switch (intent.getIntExtra("notif", 0)) {
        case 1:
            showhide = true;
            break;
        case 2:
            showhide = false;
            break;
        }
        if (showhide) {
            Notification.Builder mBuilder = new Notification.Builder(localContext)
                    .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Hall Monitor")
                    .setContentText("Debugging is fun!");

            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(42, mBuilder.build());
        } else {
            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.cancel(42);
        }
    }
    mStateManager.releaseCPUGlobal();
}

From source file:com.firefly.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    LOGD(TAG, "onCreate()");
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    mBroadcastReceiver = new BroadcastReceiver() {

        @Override//from   w  w w. j a v  a  2s .  co m
        public void onReceive(Context context, Intent intent) {
            LOGD(TAG, "onReceive(): " + intent.getAction());
        }
    };

    registerReceiver(mBroadcastReceiver, filter);

    readPersistedData();
    mCastManager = VideoCastManager.initialize(this, mApplicationId, mTargetActivity, mDataNamespace);
    if (!mCastManager.isConnected()) {
        mCastManager.reconnectSessionIfPossible(this, false);
    }
    mConsumer = new VideoCastConsumerImpl() {
        @Override
        public void onApplicationDisconnected(int errorCode) {
            LOGD(TAG, "onApplicationDisconnected() was reached");
            stopSelf();
        }

        @Override
        public void onRemoteMediaPlayerStatusUpdated() {
            int mediaStatus = mCastManager.getPlaybackStatus();
            VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus);
        }

    };
    mCastManager.addVideoCastConsumer(mConsumer);
}