List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:com.ichi2.anki.DeckPicker.java
/** * Show a message when the SD card is ejected *//*from w w w .jav a2 s. co m*/ private void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) { onSdCardNotMounted(); } else if (intent.getAction().equals(SdCardReceiver.MEDIA_MOUNT)) { restartActivity(); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SdCardReceiver.MEDIA_EJECT); iFilter.addAction(SdCardReceiver.MEDIA_MOUNT); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.csipsimple.service.SipService.java
private void registerServiceBroadcasts() { if (serviceReceiver == null) { IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(SipManager.ACTION_DEFER_OUTGOING_UNREGISTER); intentfilter.addAction(SipManager.ACTION_OUTGOING_UNREGISTER); serviceReceiver = new BroadcastReceiver() { @Override/*from w ww . j av a 2 s.c o m*/ public void onReceive(Context context, Intent intent) { Log.d("checkIntent", "intent:" + intent.getAction()); String action = intent.getAction(); if (action.equals(SipManager.ACTION_OUTGOING_UNREGISTER)) { unregisterForOutgoing( (ComponentName) intent.getParcelableExtra(SipManager.EXTRA_OUTGOING_ACTIVITY)); } else if (action.equals(SipManager.ACTION_DEFER_OUTGOING_UNREGISTER)) { deferUnregisterForOutgoing( (ComponentName) intent.getParcelableExtra(SipManager.EXTRA_OUTGOING_ACTIVITY)); } } }; registerReceiver(serviceReceiver, intentfilter); } }
From source file:com.csipsimple.service.SipService.java
/** * Register broadcast receivers.//from ww w .ja v a2 s .c o m */ private void registerBroadcasts() { // Register own broadcast receiver if (deviceStateReceiver == null) { IntentFilter intentfilter = new IntentFilter(); intentfilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentfilter.addAction(SipManager.ACTION_SIP_ACCOUNT_CHANGED); intentfilter.addAction(SipManager.ACTION_SIP_ACCOUNT_DELETED); intentfilter.addAction(SipManager.ACTION_SIP_CAN_BE_STOPPED); intentfilter.addAction(SipManager.ACTION_SIP_REQUEST_RESTART); intentfilter.addAction(DynamicReceiver4.ACTION_VPN_CONNECTIVITY); if (Compatibility.isCompatible(5)) { deviceStateReceiver = new DynamicReceiver5(this); } else { deviceStateReceiver = new DynamicReceiver4(this); } registerReceiver(deviceStateReceiver, intentfilter); deviceStateReceiver.startMonitoring(); } // Telephony if (phoneConnectivityReceiver == null) { Log.d(THIS_FILE, "Listen for phone state "); phoneConnectivityReceiver = new ServicePhoneStateReceiver(); telephonyManager.listen(phoneConnectivityReceiver, /*PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | */PhoneStateListener.LISTEN_CALL_STATE); } // Content observer if (statusObserver == null) { statusObserver = new AccountStatusContentObserver(serviceHandler); getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, statusObserver); } }
From source file:com.mobiletin.inputmethod.indic.LatinIME.java
@Override public void onCreate() { Settings.init(this); DebugFlags.init(PreferenceManager.getDefaultSharedPreferences(this)); RichInputMethodManager.init(this); mRichImm = RichInputMethodManager.getInstance(); SubtypeSwitcher.init(this); KeyboardSwitcher.init(this); AudioAndHapticFeedbackManager.init(this); AccessibilityUtils.init(this); StatsUtils.init(this); checkForTransliteration();/*from w w w . ja va 2s. c o m*/ super.onCreate(); mHandler.onCreate(); DEBUG = DebugFlags.DEBUG_ENABLED; // TODO: Resolve mutual dependencies of {@link #loadSettings()} and {@link #initSuggest()}. loadSettings(); resetSuggest(); // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. final IntentFilter filter = new IntentFilter(); //filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); registerReceiver(mConnectivityAndRingerModeChangeReceiver, filter); final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); packageFilter.addDataScheme(SCHEME_PACKAGE); registerReceiver(mDictionaryPackInstallReceiver, packageFilter); final IntentFilter newDictFilter = new IntentFilter(); newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION); registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); final IntentFilter dictDumpFilter = new IntentFilter(); dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION); registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter); DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this); StatsUtils.onCreate(mSettings.getCurrent()); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();//from w w w .j a v a 2 s. co m boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command"); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log"); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats"); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for interactive state changes last_interactive = Util.isInteractive(this); IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED); registerReceiver(interactiveStateReceiver, ifInteractive); // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); } // 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); // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. * The intent will call closeExternalStorageFiles() if the external media * is going to be ejected, so applications can clean up any files they have open. *//*w w w .jav a2 s.co m*/ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = MusicUtils.getCardId(MediaPlaybackService.this); reloadQueue(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme("file"); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
@Override public void onCreate() { super.onCreate(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rec); Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON); i.setComponent(rec);/*ww w .java 2 s. c o m*/ PendingIntent pi = PendingIntent.getBroadcast(this /*context*/, 0 /*requestCode, ignored*/, i /*intent*/, 0 /*flags*/); mRemoteControlClient = new RemoteControlClient(pi); mAudioManager.registerRemoteControlClient(mRemoteControlClient); int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; mRemoteControlClient.setTransportControlFlags(flags); mPreferences = getSharedPreferences("Music", MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); // Needs to be done in this thread, since otherwise ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); registerReceiver(mIntentReceiver, commandFilter); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:mp.teardrop.PlaybackService.java
@Override public void onCreate() { HandlerThread thread = new HandlerThread("PlaybackService", Process.THREAD_PRIORITY_DEFAULT); thread.start();/*w ww. ja v a 2 s .c o m*/ mTimeline = new SongTimeline(this); mTimeline.setCallback(this); int state = loadState(); mPlayCounts = new PlayCountsHelper(this); mMediaPlayer = getNewMediaPlayer(); mBastpUtil = new BastpUtil(); mReadahead = new ReadaheadThread(); mReadahead.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); SharedPreferences settings = getSettings(this); settings.registerOnSharedPreferenceChangeListener(this); mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1")); mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false); mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0; Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_ANDROID, true) ? Song.mCoverLoadMode | Song.COVER_MODE_ANDROID : Song.mCoverLoadMode & ~(Song.COVER_MODE_ANDROID); Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_VANILLA, true) ? Song.mCoverLoadMode | Song.COVER_MODE_VANILLA : Song.mCoverLoadMode & ~(Song.COVER_MODE_VANILLA); Song.mCoverLoadMode = settings.getBoolean(PrefKeys.COVERLOADER_SHADOW, true) ? Song.mCoverLoadMode | Song.COVER_MODE_SHADOW : Song.mCoverLoadMode & ~(Song.COVER_MODE_SHADOW); mHeadsetOnly = settings.getBoolean(PrefKeys.HEADSET_ONLY, false); mStockBroadcast = settings.getBoolean(PrefKeys.STOCK_BROADCAST, false); mInvertNotification = settings.getBoolean(PrefKeys.NOTIFICATION_INVERTED_COLOR, false); mNotificationAction = createNotificationAction(settings); mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true); mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false) ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong) : Action.Nothing; mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f; mReplayGainTrackEnabled = settings.getBoolean(PrefKeys.ENABLE_TRACK_REPLAYGAIN, false); mReplayGainAlbumEnabled = settings.getBoolean(PrefKeys.ENABLE_ALBUM_REPLAYGAIN, false); mReplayGainBump = settings.getInt(PrefKeys.REPLAYGAIN_BUMP, 75); /* seek bar is 150 -> 75 == middle == 0 */ mReplayGainUntaggedDeBump = settings.getInt(PrefKeys.REPLAYGAIN_UNTAGGED_DEBUMP, 150); /* seek bar is 150 -> == 0 */ mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TeardropMusicLock"); mReceiver = new Receiver(); IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mReceiver, filter); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mObserver); CompatIcs.registerRemote(this, mAudioManager); mLooper = thread.getLooper(); mHandler = new Handler(mLooper, this); initWidgets(); updateState(state); setCurrentSong(0, false); sInstance = this; synchronized (sWait) { sWait.notifyAll(); } mAccelFiltered = 0.0f; mAccelLast = SensorManager.GRAVITY_EARTH; setupSensor(); }
From source file:me.spadival.podmode.PodModeService.java
@Override public void onCreate() { IntentFilter usbFilter = new IntentFilter(); usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); usbFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, usbFilter); // mProvider = RemoteMetadataProvider.getInstance(this); // mProvider.setOnMetadataChangeListener(mMetadataListner); // mProvider.acquireRemoteControls(); LocalBroadcastManager bManager = LocalBroadcastManager.getInstance(this); IntentFilter notifyFilter = new IntentFilter(); notifyFilter.addAction(NOTIFYACTION); bManager.registerReceiver(mNotifyReceiver, notifyFilter); mSerialHost = new FTDriver((UsbManager) getSystemService(Context.USB_SERVICE)); mSerialDevice = new FT311UARTInterface(this, null); // Get the local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); mBluetoothDevice = null;// ww w .ja v a 2 s . c om /* // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { if (device.getName().equals("PodModeBT")) mBluetoothDevice = device; } } if (mBluetoothDevice != null) { mBTDevice = new BluetoothSerialService(this, mHandler); mBTDevice.connect(mBluetoothDevice); } */ // Create the Wifi lock (this does not acquire the lock, this just // creates it) mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // Create the retriever and start an asynchronous task that will prepare // it. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mRetriever = new MusicRetriever(getContentResolver(), getApplicationContext(), true, prefs); // mRetriever.switchToMainPlaylist(); prefs.registerOnSharedPreferenceChangeListener((OnSharedPreferenceChangeListener) this); mNowPlaying = prefs.getInt("nowplaying", 0); String mBaudrate = prefs.getString("baud_rate", "57600"); if (mBaudrate.equals("57600")) mSerialBaudRate = FTDriver.BAUD57600; else if (mBaudrate.equals("38400")) mSerialBaudRate = FTDriver.BAUD38400; else if (mBaudrate.equals("19200")) mSerialBaudRate = FTDriver.BAUD19200; (new PrepareMusicRetrieverTask(mRetriever, this)).execute(); // create the Audio Focus Helper, if the Audio Focus feature is // available (SDK 8 or above) if (android.os.Build.VERSION.SDK_INT >= 8) mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this); else mAudioFocus = AudioFocus.Focused; // no focus feature, so we always // "have" audio focus boolean wakeLockPreferred = prefs.getBoolean("wakelock", false); if (podWakeLock == null && wakeLockPreferred) { PowerManager powerMgr = (PowerManager) getSystemService(Context.POWER_SERVICE); podWakeLock = powerMgr.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, WAKETAG); podWakeLock.acquire(); } PackageManager pxm = getPackageManager(); Intent mediaIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); List<ResolveInfo> mAppsInfo = pxm.queryBroadcastReceivers(mediaIntent, 0); mSimpleRemoteApp = prefs.getString("selectapp", null); mAdvancedRemoteApp = prefs.getString("selectadvancedapp", PACKAGENAME); // Make sure App preferences are still valid and Apps haven't been // uninstalled. if (mAppsInfo.size() > 0) { CharSequence[] entryValues = new CharSequence[mAppsInfo.size()]; CharSequence[] advEntryValues = new CharSequence[mAppsInfo.size() + 1]; advEntryValues[0] = PACKAGENAME; int i = 0; for (ResolveInfo info : mAppsInfo) { entryValues[i] = (String) info.activityInfo.packageName; advEntryValues[i + 1] = (String) info.activityInfo.packageName; i++; } boolean entryFound = false; if (mSimpleRemoteApp != null) { for (i = 0; i < entryValues.length; i++) { if (mSimpleRemoteApp.equals(entryValues[i])) { entryFound = true; } } } if (!entryFound) { SharedPreferences.Editor editor = prefs.edit(); editor.putString("selectapp", (String) entryValues[0]); editor.commit(); mSimpleRemoteApp = (String) entryValues[0]; } entryFound = false; if (mAdvancedRemoteApp != null) { for (i = 0; i < advEntryValues.length; i++) { if (mAdvancedRemoteApp.equals(advEntryValues[i])) { entryFound = true; } } } if (!entryFound) { SharedPreferences.Editor editor = prefs.edit(); editor.putString("selectadvancedapp", (String) advEntryValues[0]); editor.commit(); mAdvancedRemoteApp = (String) advEntryValues[0]; } } else { SharedPreferences.Editor editor = prefs.edit(); editor.putString("selectadvancedapp", PACKAGENAME); editor.commit(); mAdvancedRemoteApp = PACKAGENAME; } mAccessoryName = prefs.getString("accessoryName", null); mAccessoryMnf = prefs.getString("accessoryMnf", null); mAccessoryModel = prefs.getString("accessoryModel", null); }