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:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

@Override
protected void onResume() {
    super.onResume();

    mConvoView.setSelected(true);//from w ww . j a  v  a 2 s  .co  m

    IntentFilter regFilter = new IntentFilter();
    regFilter.addAction(Intent.ACTION_SCREEN_OFF);
    regFilter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(receiver, regFilter);

    if (mConvoView.getOtrSessionStatus() == SessionStatus.ENCRYPTED && (!mConvoView.isOtrSessionVerified())) {

        Snackbar sb = Snackbar.make(mConvoView.getHistoryView(), R.string.not_verified, Snackbar.LENGTH_LONG);

        sb.setAction(R.string.ok, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mConvoView.showVerifyDialog();
            }
        });

        sb.show();
        ;

    }

}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    T.UI();/*from ww w  .  j a v  a2s .c  o m*/
    createWorkerThread();
    mUIHandler = new Handler();
    T.setUIThread("RegistrationProcedureActivity.onCreate()");
    setTitle(R.string.registration_title);

    mHttpClient = HTTPUtil.getHttpClient(HTTP_TIMEOUT, HTTP_RETRY_COUNT);

    final IntentFilter filter = new IntentFilter(MainService.INTENT_BEACON_SERVICE_CONNECTED);
    filter.addAction(RegistrationWizard2.INTENT_GOT_BEACON_REGIONS);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(mBroadcastReceiver, filter);

    startRegistrationService();

    // TODO: This has to be improved.
    // If the app relies on GCM the user should not be able to register.
    if (CloudConstants.USE_GCM_KICK_CHANNEL)
        GoogleServicesUtils.checkPlayServices(this);

}

From source file:cc.echonet.coolmicapp.MainActivity.java

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

    setContentView(R.layout.home);/* w  ww  .  ja va2 s .co  m*/
    timerValue = (TextView) findViewById(R.id.timerValue);
    BroadcastReceiver mPowerKeyReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String strAction = intent.getAction();
            if (strAction.equals(Intent.ACTION_SCREEN_OFF) || strAction.equals(Intent.ACTION_SCREEN_ON)
                    || strAction.equals(Intent.ACTION_USER_PRESENT)) {
                if (isThreadOn) {
                    RedFlashLight();
                }
            }
        }
    };
    final IntentFilter theFilter = new IntentFilter();
    /** System Defined Broadcast */
    theFilter.addAction(Intent.ACTION_SCREEN_ON);
    theFilter.addAction(Intent.ACTION_SCREEN_OFF);
    theFilter.addAction(Intent.ACTION_USER_PRESENT);

    getApplicationContext().registerReceiver(mPowerKeyReceiver, theFilter);

    imageView1 = (ImageView) findViewById(R.id.imageView1);

    Log.v("onCreate", (imageView1 == null ? "iv null" : "iv ok"));

    android.view.ViewGroup.LayoutParams layoutParams = imageView1.getLayoutParams();

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        layoutParams.height = 400;
    } else {
        layoutParams.height = 180;
    }

    imageView1.setLayoutParams(layoutParams);

    myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE);
    start_button = (Button) findViewById(R.id.start_recording_button);
    stop_button = (Button) findViewById(R.id.stop_recording_button);
    buttonColor = start_button.getBackground();
    logArea = (TextView) findViewById(R.id.log_area);
    logArea.setMovementMethod(new ScrollingMovementMethod());

    coolmic = new CoolMic(this, "default");

    if (Wrapper.getState() == Wrapper.WrapperInitializationStatus.WRAPPER_UNINITIALIZED) {
        if (Wrapper.init() == Wrapper.WrapperInitializationStatus.WRAPPER_INITIALIZATION_ERROR) {
            Log.d("WrapperInit", Wrapper.getInitException().toString());
            Toast.makeText(getApplicationContext(),
                    "Could not initialize native components :( Blocking controls!", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(), "Native components initialized!", Toast.LENGTH_SHORT)
                    .show();
        }
    } else if (Wrapper.init() == Wrapper.WrapperInitializationStatus.WRAPPER_INITIALIZATION_ERROR) {
        Toast.makeText(getApplicationContext(),
                "Previous problem detected with native components :( Blocking controls!", Toast.LENGTH_SHORT)
                .show();
    } else if (Wrapper.init() != Wrapper.WrapperInitializationStatus.WRAPPER_INTITIALIZED) {
        Toast.makeText(getApplicationContext(), "Native components in unknown state!", Toast.LENGTH_SHORT)
                .show();
    }

    txtListeners = (TextView) findViewById(R.id.txtListeners);
    IntentFilter mStatusIntentFilter = new IntentFilter(Constants.BROADCAST_STREAM_STATS_SERVICE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mStreamStatsReceiver, mStatusIntentFilter);
}

From source file:org.mariotaku.twidere.service.RefreshService.java

@Override
public void onCreate() {
    super.onCreate();
    GeneralComponentHelper.build(this).inject(this);
    mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0);
    mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_NOTIFICATIONS), 0);
    mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0);
    mPendingRefreshTrendsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_TRENDS), 0);
    final IntentFilter refreshFilter = new IntentFilter(BROADCAST_NOTIFICATION_DELETED);
    refreshFilter.addAction(BROADCAST_REFRESH_HOME_TIMELINE);
    refreshFilter.addAction(BROADCAST_REFRESH_NOTIFICATIONS);
    refreshFilter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_HOME_TIMELINE_REFRESHING);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_MENTIONS_REFRESHING);
    refreshFilter.addAction(BROADCAST_RESCHEDULE_DIRECT_MESSAGES_REFRESHING);
    registerReceiver(mStateReceiver, refreshFilter);
    final IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    batteryFilter.addAction(Intent.ACTION_BATTERY_OKAY);
    batteryFilter.addAction(Intent.ACTION_BATTERY_LOW);
    batteryFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    batteryFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    final IntentFilter screenFilter = new IntentFilter();
    screenFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenFilter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mPowerStateReceiver, batteryFilter);
    registerReceiver(mScreenStateReceiver, screenFilter);
    PowerStateReceiver.setServiceReceiverStarted(true);
    if (Utils.hasAutoRefreshAccounts(this)) {
        startAutoRefresh();/*from ww  w  .  jav a 2s . co  m*/
    } else {
        stopSelf();
    }
}

From source file:fm.krui.kruifm.StreamFragment.java

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

    // Initialize screen lock/wake receiver
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver screenReceiver = new ScreenReceiver();

    // Attach it to this activity
    getActivity().getApplicationContext().registerReceiver(screenReceiver, filter);

}

From source file:eu.faircode.netguard.SinkholeService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Create");

    HandlerThread thread = new HandlerThread(getString(R.string.app_name));
    thread.start();/*from w  ww . j  ava 2s .c  om*/

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    // Listen for interactive state changes
    IntentFilter ifInteractive = new IntentFilter();
    ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
    ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(interactiveStateReceiver, ifInteractive);

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageAddedReceiver, ifPackage);
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

private void handleNonScheme(String action) {
    if (Intent.ACTION_SCREEN_OFF.equals(action)) {
        onScreenOff();/*from   w  w w.  ja v a 2s.  c om*/
    } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
        onScreenOn();
    } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
        if (!SystemHook.isSupported()) {
            PreventListUtils.notifyNotSupported(mContext);
        } else if (!PreventListUtils.getInstance().canLoad(mContext)) {
            PreventListUtils.notifyNoPrevents(mContext);
        }
    }
}

From source file:org.zywx.wbpalmstar.platform.push.PushService.java

private void onReceive() {
    final String CONNECTIVITY_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(CONNECTIVITY_CHANGE_ACTION);
    registerReceiver(new BroadcastReceiver() {

        @Override/*from   w  ww.  ja v  a2  s.co  m*/
        public void onReceive(Context context, Intent intent) {
            if ("android.intent.action.SCREEN_OFF".equals(intent.getAction())) {
                if (isTemporary) {
                    sleepTime = 1000 * 60 * 2;
                } else {
                    sleepTime = 1000 * 60 * 15;
                }

                notifiTimer();
            } else if ("android.intent.action.SCREEN_ON".equals(intent.getAction())) {
                if (isTemporary) {
                    sleepTime = 1000 * 30;
                } else {
                    sleepTime = 1000 * 60 * 2;
                }

                notifiTimer();
            }
            if (TextUtils.equals(intent.getAction(), CONNECTIVITY_CHANGE_ACTION)) {

                ConnectivityManager mConnMgr = (ConnectivityManager) context
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                if (mConnMgr != null) {

                    NetworkInfo aActiveInfo = mConnMgr.getActiveNetworkInfo(); // ??
                    if (aActiveInfo != null && aActiveInfo.isConnectedOrConnecting()) {

                        if (!isSend && aActiveInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                            // udpReg();
                            // notifiUDPTimer();
                            isSend = true;
                        }
                    } else {
                        isSend = false;
                    }

                } else {
                    isSend = false;
                }

            }

        }
    }, filter);
}

From source file:org.linphone.LinphoneService.java

@Override
public void onCreate() {
    super.onCreate();
    theLinphone = this;

    // Dump some debugging information to the logs
    Hacks.dumpDeviceInformation();/*from w w  w.j  a v  a 2s  . co m*/
    addCallListner();
    //      tryTogetLastReceive();
    //      tryTogetLastRequest();
    tryKeepOnline();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis());
    mNotification.iconLevel = IC_LEVEL_ORANGE;
    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    Intent notificationIntent = new Intent(this, MainViewActivity.class);
    mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    try {
        copyAssetsFromPackage();

        mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC,
                LINPHONE_FACTORY_RC, null);

        mLinphoneCore.setPlaybackGain(3);
        mLinphoneCore.setRing(null);

        try {
            initFromConf();
        } catch (LinphoneException e) {
            Log.w(TAG, "no config ready yet");
        }
        TimerTask lTask = new TimerTask() {
            @Override
            public void run() {
                mLinphoneCore.iterate();
            }

        };

        mTimer.scheduleAtFixedRate(lTask, 0, 100);
        IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        lFilter.addAction(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mKeepAliveMgrReceiver, lFilter);

    } catch (Exception e) {
        Log.e(TAG, "Cannot start linphone", e);
    }

}

From source file:com.paywith.ibeacon.service.IBeaconService.java

@Override
public void onCreate() {
    //Log.i(TAG, "iBeaconService version "+ BuildConfig.VERSION_NAME+" is starting up");
    getBluetoothAdapter();//from  www  .  jav  a2 s  . c o  m
    bluetoothCrashResolver = new BluetoothCrashResolver(this);
    bluetoothCrashResolver.start();

    setupApiConnection();

    // Look for simulated scan data
    try {
        Class klass = Class.forName("com.paywith.ibeacon.SimulatedScanData");
        java.lang.reflect.Field f = klass.getField("iBeacons");
        this.simulatedScanData = (List<IBeacon>) f.get(null);
    } catch (ClassNotFoundException e) {
        if (IBeaconManager.debug)
            Log.d(TAG, "No com.paywith.ibeacon.SimulatedScanData class exists.");
    } catch (Exception e) {
        Log.e(TAG,
                "Cannot get simulated Scan data.  Make sure your com.paywith.ibeacon.SimulatedScanData class defines a field with the signature 'public static List<IBeacon> iBeacons'",
                e);
    }

    IntentFilter theFilter = new IntentFilter();
    theFilter.addAction(Intent.ACTION_SCREEN_OFF);
    theFilter.addAction(Intent.ACTION_SCREEN_ON);
    this.context = this.getBaseContext();
    settings = context.getSharedPreferences(PREFERENCES, 0);
    editor = settings.edit();
}