List of usage examples for android.content Intent ACTION_SCREEN_OFF
String ACTION_SCREEN_OFF
To view the source code for android.content Intent ACTION_SCREEN_OFF.
Click Source Link
From source file:com.saulcintero.moveon.services.MoveOnService.java
@Override public void onCreate() { super.onCreate(); mContext = getApplicationContext();/* w w w . ja va 2s .c o m*/ prefs = PreferenceManager.getDefaultSharedPreferences(mContext); tts = TextToSpeechUtils.getInstance(); tts.initTTS(mContext); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); showNotification(); bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(); mHandler.postDelayed(mRunnable, 0); acquireWakeLock(); mStepDetector = new StepDetector(); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); registerDetector(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mComponentName = new ComponentName(getPackageName(), MediaButtonEventReceiver.class.getName()); mSettingsObserver = new SettingsObserver(this, mContext, mComponentName); mContentResolver = getContentResolver(); mContentResolver.registerContentObserver(Settings.System.getUriFor(MEDIA_BUTTON_RECEIVER), false, mSettingsObserver); registerMediaButtonReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(mReceiverScreenOff, filter); IntentFilter filter2 = new IntentFilter("android.intent.action.ACTION_SCREEN_REFRESH"); registerReceiver(mReceiverRefreshScreenPreferences, filter2); IntentFilter filter3 = new IntentFilter("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION"); registerReceiver(mReceiverSayInformation, filter3); IntentFilter filter4 = new IntentFilter("android.intent.action.STEP_COUNTER"); registerReceiver(mReceiverStepCounter, filter4); IntentFilter filter5 = new IntentFilter("android.intent.action.BEAT_COUNTER"); registerReceiver(mReceiverBeatCounter, filter5); IntentFilter filter6 = new IntentFilter("android.intent.action.EMPTY_SENSOR_MANAGER"); registerReceiver(mReceiverEmptySensorManager, filter6); IntentFilter filter7 = new IntentFilter("android.intent.action.ACTION_PLAY_SOUND"); registerReceiver(mReceiverPlaySound, filter7); IntentFilter filter8 = new IntentFilter("android.intent.action.ACTION_REFRESH_SENSITIVITY"); registerReceiver(mReceiverRefreshSensitivity, filter8); IntentFilter filter9 = new IntentFilter("android.intent.action.CADENCE"); registerReceiver(mReceiverCadence, filter9); IntentFilter filter10 = new IntentFilter("android.intent.action.REGISTER_MEDIA_BUTTON_STATUS"); registerReceiver(mReceiverRegisterMediaButton, filter10); IntentFilter filter11 = new IntentFilter("android.intent.action.UNREGISTER_MEDIA_BUTTON_STATUS"); registerReceiver(mReceiverUnregisterMediaButton, filter11); mStepCounter = new StepCounter(mContext); mStepDetector.addStepListener(mStepCounter); mTimeManager = new TimeManager(mContext); mDistanceManager = new DistanceManager(mContext); locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); listener = new mGpsListener(); locListener = new mLocationListener(); locMgr.addGpsStatusListener(listener); locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_UPDATE_TIME_INTERVAL, GPS_UPDATE_DISTANCE_INTERVAL, locListener); }
From source file:com.dudu.aios.ui.activity.MainRecordActivity.java
private void registerScreenReceiver() { mScreenReceiver = new ScreenReceiver(); IntentFilter filter = new IntentFilter(); // ???/* w w w. jav a 2 s. c o m*/ filter.addAction(Intent.ACTION_SCREEN_OFF); // ?? filter.addAction(Intent.ACTION_SCREEN_ON); // ?? filter.addAction(Intent.ACTION_USER_PRESENT); // ?????? // example????????? // ????pad?? filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mScreenReceiver, filter); }
From source file:com.av.remusic.service.MediaService.java
@Override public void onCreate() { if (D)/* ww w . ja v a 2s. co m*/ Log.d(TAG, "Creating service"); super.onCreate(); mGetUrlThread.start(); mLrcThread.start(); mProxy = new MediaPlayerProxy(this); mProxy.init(); mProxy.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setUpMediaSession(); } mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); filter.addAction(TRY_GET_TRACKINFO); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(LOCK_SCREEN); filter.addAction(SEND_PROGRESS); filter.addAction(SETQUEUE); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MediaService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:net.kidlogger.kidlogger.KLService.java
public void setupLogging() { // Set up GPS / Network logging if (Settings.loggingGps(this)) { startGpsUpdates();/*from w w w. ja v a 2 s .c o m*/ gpsOn = true; } // Set up WiFi logging if (Settings.loggingWifi(this)) { wifiReceiver = new WifiReceiver(this); registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); wifiOn = true; } // Set up SMS logging if (Settings.loggingSms(this)) { smsObserver = new SmsObserver(this, handlering); IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED); registerReceiver(smsObserver.inSms, smsFilter); smsOn = true; } // Set up Calls logging if (Settings.loggingCalls(this)) { IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); callsReceiver = new CallsReceiver(this); registerReceiver(callsReceiver, callsFilter); callOn = true; } // Set up Idle logging IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; /*if(Settings.loggingIdle(this)){ IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; }*/ // Set up URL logging if (Settings.loggingUrl(this)) { urlObserver = new HistoryObserver(this, handlering); urlOn = true; } // Set up USB logging if (Settings.loggingUsb(this)) { IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED); usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED); usbReceiver = new UsbReceiver(this); registerReceiver(usbReceiver, usbFilter); usbOn = true; } // Set up Tasks logging if (logTask) { // Check if a new Application was started taskScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanTask(); } }).start(); if (userPresent) { handleTask.postDelayed(this, SCAN_TASK_TIME); scanningTask = true; } else { scanningTask = false; } } }; handleTask.postDelayed(taskScan, SCAN_TASK_TIME); taskOn = true; } // Set up Clipboard logging if (logClip) { // Scan clipboard content, only first 30 characters clipboardScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanClipboard(); } }).start(); if (userPresent) { handleClipb.postDelayed(this, SCAN_CLIP_TIME); scanningClip = true; } else { scanningClip = false; } } }; handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME); clipOn = true; } // Set up Power logging if (Settings.loggingPower(this)) { IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); powerReceiver = new ShutdownReceiver(this); registerReceiver(powerReceiver, powerFilter); powerOn = true; } // Set up Memory Card logging if (Settings.loggingMedia(this)) { IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED); mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED); mediaFilter.addDataScheme("file"); mediaReceiver = new MediaReceiver(this); registerReceiver(mediaReceiver, mediaFilter); mediaOn = true; } // Set up GSM logging if (Settings.loggingGsm(this)) { gsmObserver = new GsmObserver(this); telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telManager.listen(gsmObserver, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION); gsmOn = true; } // Set up Airplane mode receiver if (Settings.loggingAir(this)) { IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); airReceiver = new AirplaneReceiver(this); registerReceiver(airReceiver, airFilter); airOn = true; } // Set up Photos logging if (Settings.loggingPhotos(this)) { photoObserver = new PhotoObserver(this, this, handlering); photoOn = true; } // Set up SliceMultimediaFile if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) { mediaSlicer = new SliceMultimediaFile(this); } // Set up ConnectivityReceiver mConReceiver = new ConnectivityReceiver(this); registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); // Ser up CallIntentReceiver //outCallReceiver = new CallIntentReceiver(); //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL)); }
From source file:org.musicmod.android.app.MusicPlaybackActivity.java
@Override public void onStart() { super.onStart(); paused = false;/*from w ww. j a va2 s. c om*/ mToken = MusicUtils.bindToService(this, this); if (mToken == null) { // something went wrong mHandler.sendEmptyMessage(QUIT); } loadPreferences(); if (mBlurBackground) { getWindow().addFlags(LayoutParams.FLAG_BLUR_BEHIND); } else { getWindow().clearFlags(LayoutParams.FLAG_BLUR_BEHIND); } if (mLyricsWakelock) { getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); } else { getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); } try { float mTransitionAnimation = Settings.System.getFloat(this.getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE); if (mTransitionAnimation > 0.0) { mShowFadeAnimation = true; } else { mShowFadeAnimation = false; } } catch (SettingNotFoundException e) { e.printStackTrace(); } IntentFilter f = new IntentFilter(); f.addAction(BROADCAST_PLAYSTATE_CHANGED); f.addAction(BROADCAST_META_CHANGED); f.addAction(BROADCAST_FAVORITESTATE_CHANGED); registerReceiver(mStatusListener, new IntentFilter(f)); IntentFilter s = new IntentFilter(); s.addAction(Intent.ACTION_SCREEN_ON); s.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mScreenTimeoutListener, new IntentFilter(s)); long next = refreshNow(); queueNextRefresh(next); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
@Override protected void onResume() { super.onResume(); // Check if permissions were revoked checkPermissions();/*w w w . j av a 2 s. co m*/ // Listen for preference changes SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); // 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); if (Util.hasPhoneStatePermission(this)) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE); phone_state = true; } }
From source file:eu.faircode.netguard.ActivitySettings.java
@Override protected void onResume() { super.onResume(); checkPermissions(null);/*from w w w. j a v a 2 s .c o m*/ // Listen for preference changes SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); // 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); }
From source file:org.yammp.app.MusicPlaybackActivity.java
@Override public void onStart() { super.onStart(); paused = false;/*from w ww .j a va 2s . c om*/ mToken = MusicUtils.bindToService(this, this); if (mToken == null) { // something went wrong mHandler.sendEmptyMessage(QUIT); } loadPreferences(); if (mBlurBackground) { getWindow().addFlags(LayoutParams.FLAG_BLUR_BEHIND); } else { getWindow().clearFlags(LayoutParams.FLAG_BLUR_BEHIND); } if (mLyricsWakelock) { getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); } else { getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON); } try { float mTransitionAnimation = Settings.System.getFloat(getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE); if (mTransitionAnimation > 0.0) { mShowFadeAnimation = true; } else { mShowFadeAnimation = false; } } catch (SettingNotFoundException e) { e.printStackTrace(); } IntentFilter f = new IntentFilter(); f.addAction(BROADCAST_PLAYSTATE_CHANGED); f.addAction(BROADCAST_META_CHANGED); f.addAction(BROADCAST_FAVORITESTATE_CHANGED); registerReceiver(mStatusListener, new IntentFilter(f)); IntentFilter s = new IntentFilter(); s.addAction(Intent.ACTION_SCREEN_ON); s.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mScreenTimeoutListener, new IntentFilter(s)); long next = refreshNow(); queueNextRefresh(next); }
From source file:com.av.remusic.service.MediaService.java
private void handleCommandIntent(Intent intent) { final String action = intent.getAction(); final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null; if (D)/*w w w . jav a2s . com*/ Log.d(TAG, "handleCommandIntent: action = " + action + ", command = " + command); if (CMDNEXT.equals(command) || NEXT_ACTION.equals(action)) { gotoNext(true); } else if (CMDPREVIOUS.equals(command) || PREVIOUS_ACTION.equals(action) || PREVIOUS_FORCE_ACTION.equals(action)) { prev(PREVIOUS_FORCE_ACTION.equals(action)); } else if (CMDTOGGLEPAUSE.equals(command) || TOGGLEPAUSE_ACTION.equals(action)) { if (isPlaying()) { pause(); mPausedByTransientLossOfFocus = false; } else { play(); } } else if (CMDPAUSE.equals(command) || PAUSE_ACTION.equals(action)) { pause(); mPausedByTransientLossOfFocus = false; } else if (CMDPLAY.equals(command)) { play(); } else if (CMDSTOP.equals(command) || STOP_ACTION.equals(action)) { pause(); mPausedByTransientLossOfFocus = false; seek(0); releaseServiceUiAndStop(); } else if (REPEAT_ACTION.equals(action)) { cycleRepeat(); } else if (SHUFFLE_ACTION.equals(action)) { cycleShuffle(); } else if (TRY_GET_TRACKINFO.equals(action)) { getLrc(mPlaylist.get(mPlayPos).mId); } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { if (isPlaying() && !mIsLocked) { Intent lockscreen = new Intent(this, LockActivity.class); lockscreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(lockscreen); } } else if (LOCK_SCREEN.equals(action)) { mIsLocked = intent.getBooleanExtra("islock", true); L.D(D, TAG, "isloced = " + mIsLocked); } else if (SEND_PROGRESS.equals(action)) { if (isPlaying() && !mIsSending) { mPlayerHandler.post(sendDuration); mIsSending = true; } else if (!isPlaying()) { mPlayerHandler.removeCallbacks(sendDuration); mIsSending = false; } } else if (SETQUEUE.equals(action)) { Log.e("playab", "action"); setQueuePosition(intent.getIntExtra("position", 0)); } }
From source file:saphion.services.ForegroundService.java
@SuppressWarnings("deprecation") @Override/* ww w. j a v a 2 s. com*/ public void onCreate() { mPref = ForegroundService.this.getSharedPreferences(PREF_NAME, MODE_MULTI_PROCESS); // receive ACTION_BATTERY_CHANGED. IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_POWER_CONNECTED); filter.addAction(Intent.ACTION_POWER_DISCONNECTED); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(Intents.MYBAT_INTENT); filter.addAction(Intents.TORCH_ON); filter.addAction(Intents.TORCH_OFF); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED); filter.addAction(Intents.SWITCHER_INTENT); filter.addAction(Intents.SWITCHER_NOTI); filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); } registerReceiver(mBroadcastReceiver, filter); readbattery(); mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (!mPref.getBoolean(PreferenceHelper.NOTIFICATION_ENABLE, true)) { mNM.cancelAll();// .notify(id, notification); } try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); return; } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; } try { mSetForeground = getClass().getMethod("setForeground", mSetForegroundSignature); } catch (NoSuchMethodException e) { throw new IllegalStateException("OS doesn't have Service.startForeground OR Service.setForeground!"); } }