List of usage examples for android.content Intent ACTION_SHUTDOWN
String ACTION_SHUTDOWN
To view the source code for android.content Intent ACTION_SHUTDOWN.
Click Source Link
From source file:org.fairphone.peaceofmind.PeaceOfMindBroadCastReceiver.java
@Override public void onReceive(Context context, Intent intent) { mContext = context;/*from w ww . j a v a 2s. c om*/ setupDeviceController(); String action = intent.getAction(); if (action != null) { // obtains the piece of mind data from shared preferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); mCurrentStats = PeaceOfMindStats.getStatsFromSharedPreferences(mSharedPreferences); if (action.equals(PeaceOfMindActivity.UPDATE_PEACE_OF_MIND)) { updateTargetTime(intent); } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { //only react to this if the app is running if (mCurrentStats.mIsOnPeaceOfMind) { Bundle extras = intent.getExtras(); //if the intent was sent by the system end Peace of mind if (!extras.containsKey(AirplaneModeToggler.PEACE_OF_MIND_TOGGLE)) { endPeaceOfMind(true); } } } else if (Intent.ACTION_SHUTDOWN.equals(action) && mCurrentStats.mIsOnPeaceOfMind) { endPeaceOfMind(true); } else { performTimeTick(); } } else { return; } // update the widgets updateWidget(context); }
From source file:com.mikecorrigan.bohrium.pubsub.RegistrationClient.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "onStartCommand: intent=" + intent + ", extras=" + Utils.bundleToString(intent.getExtras()) + ", flags=" + flags + ", startId=" + startId); if (intent.getAction().equals(C2DM_INTENT_REGISTRATION)) { mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_REGISTRATION_RESPONSE, intent)); GCMBroadcastReceiver.completeWakefulIntent(intent); } else if (intent.getAction().equals(C2DM_INTENT_RECEIVE)) { mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_MESSAGE, intent)); GCMBroadcastReceiver.completeWakefulIntent(intent); } else if (intent.getAction().equals(C2DM_INTENT_RETRY)) { mHandler.sendMessage(mHandler.obtainMessage(EVENT_C2DM_RETRY_REGISTRATION, intent)); GCMBroadcastReceiver.completeWakefulIntent(intent); } else if (intent.getAction().equals(Intent.ACTION_MAIN)) { if (mConfiguration == null) { mConfiguration = intent.getExtras(); }/*from w w w . j a v a2 s .com*/ mHandler.sendEmptyMessage(EVENT_INITIALIZE); } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) { mHandler.sendEmptyMessage(EVENT_UNINITIALIZE); } return RegistrationClient.START_STICKY; }
From source file:org.pixmob.freemobile.netstat.MonitorService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/*from www.j ava2s. c om*/ public void onCreate() { super.onCreate(); pm = (PowerManager) getSystemService(POWER_SERVICE); tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); prefs = getSharedPreferences(SP_NAME, MODE_PRIVATE); prefs.registerOnSharedPreferenceChangeListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final int largeIconWidth = getResources() .getDimensionPixelSize(android.R.dimen.notification_large_icon_width); final int largeIconHeight = getResources() .getDimensionPixelSize(android.R.dimen.notification_large_icon_height); if ((largeIconWidth > 0) && (largeIconHeight > 0)) { Bitmap freeLargeIconTmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify_service_free_large); if ((freeLargeIconTmp != null) && (freeLargeIconTmp.getWidth() > 0) && (freeLargeIconTmp.getHeight() > 0)) { freeLargeIcon = Bitmap.createScaledBitmap(freeLargeIconTmp, largeIconWidth, largeIconHeight, true); } Bitmap freeFemtoLargeIconTmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify_service_free_femto_large); if ((freeFemtoLargeIconTmp != null) && (freeFemtoLargeIconTmp.getHeight() > 0) && (freeFemtoLargeIconTmp.getWidth() > 0)) { freeFemtoLargeIcon = Bitmap.createScaledBitmap(freeFemtoLargeIconTmp, largeIconWidth, largeIconHeight, true); } Bitmap orangeLargeIconTmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify_service_orange_large); if ((orangeLargeIconTmp != null) && (orangeLargeIconTmp.getHeight() > 0) && (orangeLargeIconTmp.getWidth() > 0)) { orangeLargeIcon = Bitmap.createScaledBitmap(orangeLargeIconTmp, largeIconWidth, largeIconHeight, true); } } } // Initialize and start a worker thread for inserting rows into the // application database. final Context c = getApplicationContext(); pendingInsert = new ArrayBlockingQueue<>(8); new PendingInsertWorker(c, pendingInsert).start(); // This intent is fired when the application notification is clicked. openUIPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_NOTIFICATION), PendingIntent.FLAG_CANCEL_CURRENT); // This intent is only available as a Jelly Bean notification action in // order to open network operator settings. Intent networkSettingsIntent = IntentFactory.networkOperatorSettings(this); if (networkSettingsIntent != null) { networkOperatorSettingsPendingIntent = PendingIntent.getActivity(this, 0, networkSettingsIntent, PendingIntent.FLAG_CANCEL_CURRENT); } Intent wirelessSettingsIntent = IntentFactory.wirelessSettings(this); if (wirelessSettingsIntent != null) { wirelessSettingsPendingIntent = PendingIntent.getActivity(this, 0, wirelessSettingsIntent, PendingIntent.FLAG_CANCEL_CURRENT); } // Watch screen light: is the screen on? screenMonitor = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateEventDatabase(); } }; final IntentFilter screenIntentFilter = new IntentFilter(); screenIntentFilter.addAction(Intent.ACTION_SCREEN_ON); screenIntentFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(screenMonitor, screenIntentFilter); // Watch Wi-Fi connections. connectionMonitor = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (onConnectivityUpdated()) { updateEventDatabase(); } } }; final IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectionMonitor, connectionIntentFilter); // Watch mobile connections. phoneMonitor = new PhoneStateListener() { @Override public void onDataConnectionStateChanged(int state, int networkType) { updateService(); } @Override public void onServiceStateChanged(ServiceState serviceState) { if (stopServiceIfSimOperatorIsNotFreeMobile()) return; mobileNetworkConnected = (serviceState != null) && (serviceState.getState() == ServiceState.STATE_IN_SERVICE); updateService(); } @Override public void onCellInfoChanged(List<CellInfo> cellInfo) { updateService(); } private void updateService() { if (tm != null) { // Fix NPE - found by Acralyzer mobileNetworkType = tm.getNetworkType(); //update the network type to have the latest } final int phoneStateUpdated = onPhoneStateUpdated(); if (phoneStateUpdated >= 0) updateEventDatabase(); updateNotification(true, phoneStateUpdated == 1); } }; int events = PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) events |= PhoneStateListener.LISTEN_CELL_INFO; tm.listen(phoneMonitor, events); // Watch battery level. batteryMonitor = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateEventDatabase(); } }; batteryIntentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(batteryMonitor, batteryIntentFilter); shutdownMonitor = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onDeviceShutdown(); } }; final IntentFilter shutdownIntentFilter = new IntentFilter(); shutdownIntentFilter.addAction(Intent.ACTION_SHUTDOWN); // HTC devices use a different Intent action: // http://stackoverflow.com/q/5076410/422906 shutdownIntentFilter.addAction("android.intent.action.QUICKBOOT_POWEROFF"); registerReceiver(shutdownMonitor, shutdownIntentFilter); if (prefs.getBoolean(SP_KEY_ENABLE_AUTO_RESTART_SERVICE, false) && Arrays .asList(ANDROID_VERSIONS_ALLOWED_TO_AUTO_RESTART_SERVICE).contains(Build.VERSION.RELEASE)) { // Kitkat and JellyBean auto-kill service workaround // http://stackoverflow.com/a/20735519/1527491 ensureServiceStaysRunning(); } }
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.j a va 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.gaeproxy.GAEProxyService.java
@Override public void onCreate() { super.onCreate(); mShutdownReceiver = new BroadcastReceiver() { @Override//from w w w. j av a 2 s . c o m public void onReceive(Context context, Intent intent) { stopSelf(); } }; IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN); registerReceiver(mShutdownReceiver, filter); EasyTracker.getTracker().trackEvent("service", "start", getVersionName(), 0L); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); settings = PreferenceManager.getDefaultSharedPreferences(this); Intent intent = new Intent(this, GAEProxyActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new Notification(); try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); } 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!"); } }