List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:com.igniva.filemanager.activities.MainActivity.java
@Override public void onResume() { super.onResume(); if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show();//from w w w. java 2s .co m materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter("general_communications")); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } // Registering intent filter for OTG IntentFilter otgFilter = new IntentFilter(); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); }
From source file:com.amaze.filemanager.activities.MainActivity.java
@Override public void onResume() { super.onResume(); if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show();/*from ww w .j av a 2 s . c om*/ materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter("general_communications")); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } }
From source file:com.koma.music.service.MusicService.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.//ww w . j a v a2 s . co m */ public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { /** * {@inheritDoc} */ @Override public void onReceive(final Context context, final Intent intent) { final 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 = getCardId(); reloadQueue(); mQueueIsSaveable = true; notifyChange(MusicServiceConstants.QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_EJECT); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addDataScheme("file"); registerReceiver(mUnmountReceiver, filter); } }
From source file:com.irccloud.android.NetworkConnection.java
public void registerForConnectivity() { try {/*from w w w . j av a 2s. c om*/ IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); IRCCloudApplication.getInstance().getApplicationContext().registerReceiver(connectivityListener, intentFilter); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.koma.music.service.MusicService.java
/** * {@inheritDoc}// w ww .j av a 2s . com */ @Override public void onCreate() { LogUtils.d(TAG, "Creating service"); super.onCreate(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { stopSelf(); return; } else { mReadGranted = true; } mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Initialize the favorites and recents databases mRecentlyPlayCache = RecentlyPlay.getInstance(this); // gets the song play count cache mSongPlayCountCache = SongPlayCount.getInstance(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); // Initialize the image fetcher // mImageFetcher = ImageFetcher.getInstance(this); // Initialize the image cache // mImageFetcher.setImageCache(ImageCache.getInstance(this)); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt the UI. mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); // Initialize the handler mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); // Initialize the audio manager and register any headset controls for // playback mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // Use the remote control APIs to set the playback state setUpMediaSession(); // Initialize the preferences mPreferences = getSharedPreferences("MusicService", 0); mCardId = getCardId(); mShowAlbumArtOnLockscreen = mPreferences.getBoolean(PreferenceUtils.SHOW_ALBUM_ART_ON_LOCKSCREEN, false); setShakeToPlayEnabled(mPreferences.getBoolean(PreferenceUtils.SHAKE_TO_PLAY, false)); registerExternalStorageListener(); // Initialize the media player mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(MusicServiceConstants.SERVICECMD); filter.addAction(MusicServiceConstants.TOGGLEPAUSE_ACTION); filter.addAction(MusicServiceConstants.PAUSE_ACTION); filter.addAction(MusicServiceConstants.STOP_ACTION); filter.addAction(MusicServiceConstants.NEXT_ACTION); filter.addAction(MusicServiceConstants.PREVIOUS_ACTION); filter.addAction(MusicServiceConstants.PREVIOUS_FORCE_ACTION); filter.addAction(MusicServiceConstants.REPEAT_ACTION); filter.addAction(MusicServiceConstants.SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // Get events when MediaStore content changes mMediaObserver = new MediaObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaObserver); // Initialize the delayed shutdown intent final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(MusicServiceConstants.SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); // Listen for the idle state scheduleDelayedShutdown(); // Bring the queue back reloadQueue(); notifyChange(MusicServiceConstants.QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:com.bluros.music.MusicService.java
@Override public void onCreate() { if (D)//from w w w . jav a 2 s. c om Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // 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(SLEEP_MODE_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(RemoteSelectDialog.REMOTE_START_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN); filter.addAction(RemoteSelectDialog.REMOTE_CONNECT); // 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, MusicService.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:com.android.leanlauncher.LauncherTransitionable.java
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); // Listen for broadcasts related to user-presence final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); // For handling managed profiles filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED); filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED); registerReceiver(mReceiver, filter); FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); setupTransparentSystemBarsForLmp();/* ww w .j a va 2 s . c om*/ mAttached = true; mVisible = true; }
From source file:com.android.server.MountService.java
/** * Constructs a new MountService instance * * @param context Binder context for this service */// www . j a v a 2 s . c o m public MountService(Context context) { sSelf = this; mContext = context; synchronized (mVolumesLock) { readStorageListLocked(); } // XXX: This will go away soon in favor of IMountServiceObserver mPms = (PackageManagerService) ServiceManager.getService("package"); HandlerThread hthread = new HandlerThread(TAG); hthread.start(); mHandler = new MountServiceHandler(hthread.getLooper()); // Watch for user changes final IntentFilter userFilter = new IntentFilter(); userFilter.addAction(Intent.ACTION_USER_ADDED); userFilter.addAction(Intent.ACTION_USER_REMOVED); mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler); // Watch for USB changes on primary volume final StorageVolume primary = getPrimaryPhysicalVolume(); if (primary != null && primary.allowMassStorage()) { mContext.registerReceiver(mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler); } // Add OBB Action Handler to MountService thread. mObbActionHandler = new ObbActionHandler(IoThread.get().getLooper()); // Initialize the last-fstrim tracking if necessary File dataDir = Environment.getDataDirectory(); File systemDir = new File(dataDir, "system"); mLastMaintenanceFile = new File(systemDir, LAST_FSTRIM_FILE); if (!mLastMaintenanceFile.exists()) { // Not setting mLastMaintenance here means that we will force an // fstrim during reboot following the OTA that installs this code. try { (new FileOutputStream(mLastMaintenanceFile)).close(); } catch (IOException e) { Slog.e(TAG, "Unable to create fstrim record " + mLastMaintenanceFile.getPath()); } } else { mLastMaintenance = mLastMaintenanceFile.lastModified(); } /* * Create the connection to vold with a maximum queue of twice the * amount of containers we'd ever expect to have. This keeps an * "asec list" from blocking a thread repeatedly. */ mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, null); Thread thread = new Thread(mConnector, VOLD_TAG); thread.start(); // Add ourself to the Watchdog monitors if enabled. if (WATCHDOG_ENABLE) { Watchdog.getInstance().addMonitor(this); } }
From source file:com.android.tv.MainActivity.java
@Override protected void onStart() { if (DEBUG)/* w w w.j av a2s . c o m*/ Log.d(TAG, "onStart()"); super.onStart(); mScreenOffIntentReceived = false; mActivityStarted = true; mTracker.sendMainStart(); mMainDurationTimer.start(); applyParentalControlSettings(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); intentFilter.addAction(Intent.ACTION_SCREEN_OFF); intentFilter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mBroadcastReceiver, intentFilter); Intent notificationIntent = new Intent(this, NotificationService.class); notificationIntent.setAction(NotificationService.ACTION_SHOW_RECOMMENDATION); startService(notificationIntent); }
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
/** * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver) *///from ww w . j a v a2s. c om private void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (AnkiDroidApp.getSharedPrefs(getBaseContext()).getBoolean("internalMemory", false)) { return; } if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) { showDialog(DIALOG_SD_CARD_NOT_MOUNTED); } else if (intent.getAction().equals(SdCardReceiver.MEDIA_MOUNT)) { if (mNotMountedDialog != null && mNotMountedDialog.isShowing()) { mNotMountedDialog.dismiss(); } loadCollection(); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SdCardReceiver.MEDIA_EJECT); iFilter.addAction(SdCardReceiver.MEDIA_MOUNT); registerReceiver(mUnmountReceiver, iFilter); } }