List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:fr.gotorennes.AbstractMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayout());/* w w w . j a v a 2 s .c o m*/ mapView = (MapView) findViewById(R.id.mapView); mapController = mapView.getController(); myLocationOverlay = new MyLocationOverlay(this, mapView); // Add ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomControl); zoomControls.setOnZoomInClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapController.zoomIn(); onMapChange(); } }); zoomControls.setOnZoomOutClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { mapController.zoomOut(); onMapChange(); } }); addMyLocationOverlay(); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { finish(); } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AbstractActivity.ACTION_LOGOUT); registerReceiver(receiver, intentFilter); BackgroundTask<Boolean> backgroundInit = new BackgroundTask<Boolean>() { @Override protected Boolean execute() { try { goToRennes = GoToRennes.getInstance(AbstractMapActivity.this, null); } catch (Exception ex) { return false; } return true; } @Override protected void callback(Boolean result) { if (result == null || !result) { showError(getString(R.string.erreurInitialisation), true); } else { init(); goToRennes.track(getTrackingName()); } } }; backgroundInit.start(this); }
From source file:com.samsung.soundscape.util.ConnectivityManager.java
/** * Register network change listeners./* w ww .java 2s . c om*/ */ private void registerWiFiStateListener() { IntentFilter mWiFiStateFilter = new IntentFilter(); mWiFiStateFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); mWiFiStateFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); App.getInstance().registerReceiver(mWifiStateChangedReceiver, mWiFiStateFilter); }
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
@Override public void onResume() { super.onResume(); getActivity().registerReceiver(mUserBackgrounding, new IntentFilter(Intent.ACTION_USER_BACKGROUND)); IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); packageFilter.addDataScheme("package"); getActivity().registerReceiver(mPackageObserver, packageFilter); mAppListChanged = false;/*w ww .j a v a 2 s . com*/ if (mAppLoadingTask == null || mAppLoadingTask.getStatus() == AsyncTask.Status.FINISHED) { mAppLoadingTask = new AppLoadingTask().execute(); } }
From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java
@Override protected void onStart() { Log.d(LOG_TAG, "onStart"); super.onStart(); stopped = false;/*from w w w . j ava 2s. c om*/ mainMenuDelegate = new MainMenuDelegate(this); listView = (AbsListView) findViewById(android.R.id.list); listView.setOnItemClickListener(clickListener); if (listView instanceof ListView) { // It is important that this is inflated with listView passed as the parent, despite the attach false parameter. // Otherwise, the view ends up with incorrect LayoutParams and we see crazy, crazy behavior. headerView = getLayoutInflater().inflate(R.layout.header_video_list, listView, false); ListView lv = (ListView) listView; if (lv.getHeaderViewsCount() == 0) { lv.addHeaderView(headerView); } } else { // GridView, fixed header headerView = findViewById(R.id.header_video_list); } /** Responsive layout stuff * * Based on screen width, we will find either * narrow * a listview with a header view * items are a thumbnail to the left and a title on white space to the right. * header is a thumbnail with overlaid title across the bottom * * middle * a fixed header on top and a grid view below * header is thumb to left, title above scrolling description to right * items are thumbs with title overlaid across the bottom (3 across) * * wide * a fixed header to the left and a grid view on the right * header is thumb on top, title next, description at bottom * items are thumbs with title overlaid across the bottom (3 across) * * * So in this class, we * find view by id 'list' * if it's a ListView, inflate and attach header view * if not, then the header is fixed and already in the layout * either way, now we can find header views by id * adapter is the same either way * * * * **/ ActionBar ab = getActionBar(); displayOptionsAdapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, displayOptions); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle(""); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ab.setListNavigationCallbacks(displayOptionsAdapter, navListener); ab.setSelectedNavigationItem(isShowingDownloadedVideosOnly ? 1 : 0); requestDataService(new ObjectCallback<KADataService>() { @Override public void call(KADataService dataService) { VideoListActivity.this.dataService = dataService; if (topicId != null) { Dao<Topic, String> topicDao; try { topicDao = dataService.getHelper().getTopicDao(); topic = topicDao.queryForId(topicId); } catch (SQLException e) { e.printStackTrace(); } } else { Log.e(LOG_TAG, "Topic id not set for video list"); topic = dataService.getRootTopic(); topicId = topic.getId(); } thumbnailManager = dataService.getThumbnailManager(); api = dataService.getAPIAdapter(); api.registerUserUpdateListener(userUpdateListener); // This instead happens in ActionBar.OnNavigationListener#onNavigationItemSelected, which // fires after onResume. // setParentTopic(topic); } }); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_LIBRARY_UPDATE); filter.addAction(ACTION_BADGE_EARNED); filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED); filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE); filter.addAction(ACTION_TOAST); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter); thumbExecutor = Executors.newSingleThreadExecutor(); }
From source file:com.andreadec.musicplayer.MusicService.java
/** * Called when the service is created.//from w ww. j a v a2s.c om */ @Override public void onCreate() { PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicServiceWakelock"); // Initialize the telephony manager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new MusicPhoneStateListener(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Initialize pending intents quitPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.quit"), 0); previousPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.previous"), 0); playpausePendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.playpause"), 0); nextPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.andreadec.musicplayer.next"), 0); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), PendingIntent.FLAG_UPDATE_CURRENT); // Read saved user preferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Initialize the media player mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); // Enable the wake lock to keep CPU running when the screen is switched off shuffle = preferences.getBoolean(Constants.PREFERENCE_SHUFFLE, Constants.DEFAULT_SHUFFLE); repeat = preferences.getBoolean(Constants.PREFERENCE_REPEAT, Constants.DEFAULT_REPEAT); repeatAll = preferences.getBoolean(Constants.PREFERENCE_REPEATALL, Constants.DEFAULT_REPEATALL); try { // This may fail if the device doesn't support bass boost bassBoost = new BassBoost(1, mediaPlayer.getAudioSessionId()); bassBoost.setEnabled( preferences.getBoolean(Constants.PREFERENCE_BASSBOOST, Constants.DEFAULT_BASSBOOST)); setBassBoostStrength(preferences.getInt(Constants.PREFERENCE_BASSBOOSTSTRENGTH, Constants.DEFAULT_BASSBOOSTSTRENGTH)); bassBoostAvailable = true; } catch (Exception e) { bassBoostAvailable = false; } try { // This may fail if the device doesn't support equalizer equalizer = new Equalizer(1, mediaPlayer.getAudioSessionId()); equalizer.setEnabled( preferences.getBoolean(Constants.PREFERENCE_EQUALIZER, Constants.DEFAULT_EQUALIZER)); setEqualizerPreset( preferences.getInt(Constants.PREFERENCE_EQUALIZERPRESET, Constants.DEFAULT_EQUALIZERPRESET)); equalizerAvailable = true; } catch (Exception e) { equalizerAvailable = false; } random = new Random(System.nanoTime()); // Necessary for song shuffle shakeListener = new ShakeListener(this); if (preferences.getBoolean(Constants.PREFERENCE_SHAKEENABLED, Constants.DEFAULT_SHAKEENABLED)) { shakeListener.enable(); } telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Start listen for telephony events // Inizialize the audio manager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent); audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Initialize remote control client if (Build.VERSION.SDK_INT >= 14) { icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); audioManager.registerRemoteControlClient(remoteControlClient); } updateNotificationMessage(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.andreadec.musicplayer.quit"); intentFilter.addAction("com.andreadec.musicplayer.previous"); intentFilter.addAction("com.andreadec.musicplayer.previousNoRestart"); intentFilter.addAction("com.andreadec.musicplayer.playpause"); intentFilter.addAction("com.andreadec.musicplayer.next"); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals("com.andreadec.musicplayer.quit")) { sendBroadcast(new Intent("com.andreadec.musicplayer.quitactivity")); stopSelf(); return; } else if (action.equals("com.andreadec.musicplayer.previous")) { previousItem(false); } else if (action.equals("com.andreadec.musicplayer.previousNoRestart")) { previousItem(true); } else if (action.equals("com.andreadec.musicplayer.playpause")) { playPause(); } else if (action.equals("com.andreadec.musicplayer.next")) { nextItem(); } else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { if (preferences.getBoolean(Constants.PREFERENCE_STOPPLAYINGWHENHEADSETDISCONNECTED, Constants.DEFAULT_STOPPLAYINGWHENHEADSETDISCONNECTED)) { pause(); } } } }; registerReceiver(broadcastReceiver, intentFilter); if (!isPlaying()) { loadLastSong(); } startForeground(Constants.NOTIFICATION_MAIN, notification); }
From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); application = (WalletApplication) getApplication(); config = application.getConfiguration(); final Wallet wallet = application.getWallet(); peerConnectivityListener = new PeerConnectivityListener(); broadcastPeerState(0);/*ww w . j a va 2 s.co m*/ blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { log.info("blockchain does not exist, resetting wallet"); wallet.clearTransactions(0); wallet.setLastBlockSeenHeight(-1); // magic value wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (!blockChainFileExists && earliestKeyCreationTime > 0) { try { final InputStream checkpointsInputStream = getAssets() .open(Constants.Files.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { log.error("problem reading checkpoints, continuing without", x); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; log.error(msg, x); throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); }
From source file:com.facebook.LikeView.java
private void associateWithLikeActionController(LikeActionController likeActionController) { this.likeActionController = likeActionController; this.broadcastReceiver = new LikeControllerBroadcastReceiver(); LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getContext()); // add the broadcast receiver IntentFilter filter = new IntentFilter(); filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_UPDATED); filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR); filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_RESET); localBroadcastManager.registerReceiver(broadcastReceiver, filter); }
From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java
@SuppressLint("RtlHardcoded") @SuppressWarnings("deprecation") @Override//from w w w. ja v a 2s . c om protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent("com.farmerbb.taskbar.CONTEXT_MENU_APPEARING")); boolean isNonAppMenu = !getIntent().hasExtra("package_name") && !getIntent().hasExtra("app_name"); showStartMenu = getIntent().getBooleanExtra("launched_from_start_menu", false); isStartButton = isNonAppMenu && getIntent().getBooleanExtra("is_start_button", false); isOverflowMenu = isNonAppMenu && getIntent().getBooleanExtra("is_overflow_menu", false); contextMenuFix = getIntent().hasExtra("context_menu_fix"); // Determine where to position the dialog on screen WindowManager.LayoutParams params = getWindow().getAttributes(); DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE); Display display = dm.getDisplay(Display.DEFAULT_DISPLAY); int statusBarHeight = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) statusBarHeight = getResources().getDimensionPixelSize(resourceId); if (showStartMenu) { int x = getIntent().getIntExtra("x", 0); int y = getIntent().getIntExtra("y", 0); int offset = getResources().getDimensionPixelSize( isOverflowMenu ? R.dimen.context_menu_offset_overflow : R.dimen.context_menu_offset); switch (U.getTaskbarPosition(this)) { case "bottom_left": case "bottom_vertical_left": params.gravity = Gravity.BOTTOM | Gravity.LEFT; params.x = x; params.y = display.getHeight() - y - offset; break; case "bottom_right": case "bottom_vertical_right": params.gravity = Gravity.BOTTOM | Gravity.LEFT; params.x = x - getResources().getDimensionPixelSize(R.dimen.context_menu_width) + offset + offset; params.y = display.getHeight() - y - offset; break; case "top_left": case "top_vertical_left": params.gravity = Gravity.TOP | Gravity.LEFT; params.x = x; params.y = y - offset + statusBarHeight; break; case "top_right": case "top_vertical_right": params.gravity = Gravity.TOP | Gravity.LEFT; params.x = x - getResources().getDimensionPixelSize(R.dimen.context_menu_width) + offset + offset; params.y = y - offset + statusBarHeight; break; } } else { LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); int x = getIntent().getIntExtra("x", display.getWidth()); int y = getIntent().getIntExtra("y", display.getHeight()); int offset = getResources().getDimensionPixelSize(R.dimen.icon_size); switch (U.getTaskbarPosition(this)) { case "bottom_left": params.gravity = Gravity.BOTTOM | Gravity.LEFT; params.x = isStartButton ? 0 : x; params.y = offset; break; case "bottom_vertical_left": params.gravity = Gravity.BOTTOM | Gravity.LEFT; params.x = offset; params.y = display.getHeight() - y - (isStartButton ? 0 : offset); break; case "bottom_right": params.gravity = Gravity.BOTTOM | Gravity.RIGHT; params.x = display.getWidth() - x; params.y = offset; break; case "bottom_vertical_right": params.gravity = Gravity.BOTTOM | Gravity.RIGHT; params.x = offset; params.y = display.getHeight() - y - (isStartButton ? 0 : offset); break; case "top_left": params.gravity = Gravity.TOP | Gravity.LEFT; params.x = isStartButton ? 0 : x; params.y = offset; break; case "top_vertical_left": params.gravity = Gravity.TOP | Gravity.LEFT; params.x = offset; params.y = isStartButton ? 0 : y - statusBarHeight; break; case "top_right": params.gravity = Gravity.TOP | Gravity.RIGHT; params.x = display.getWidth() - x; params.y = offset; break; case "top_vertical_right": params.gravity = Gravity.TOP | Gravity.RIGHT; params.x = offset; params.y = isStartButton ? 0 : y - statusBarHeight; break; } } params.width = getResources().getDimensionPixelSize(R.dimen.context_menu_width); params.dimAmount = 0; getWindow().setAttributes(params); View view = findViewById(android.R.id.list); if (view != null) view.setPadding(0, 0, 0, 0); generateMenu(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.farmerbb.taskbar.START_MENU_APPEARING"); intentFilter.addAction("com.farmerbb.taskbar.DASHBOARD_APPEARING"); LocalBroadcastManager.getInstance(this).registerReceiver(finishReceiver, intentFilter); }
From source file:org.droidpres.activity.TransferActivity.java
public void swichWiFi() { mWiFiConnectFlag = false;//from ww w. j av a 2s. co m IntentFilter filter = mFilter; WiFiStateReceiver receiver = mWifiStateReceiver; if (receiver == null) { receiver = new WiFiStateReceiver(); mWifiStateReceiver = receiver; filter = new IntentFilter(); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); mFilter = filter; } this.registerReceiver(receiver, filter); getWiFiManager().setWifiEnabled(mWiFiFlag); if (mWiFiFlag) { new Timer().schedule(new TimerTask() { @Override public void run() { if (!mWiFiConnectFlag) { mWiFiFlag = false; getWiFiManager().setWifiEnabled(mWiFiFlag); } } }, 90000); } }
From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java
@Override public void onStart() { mDisplayName = mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_NAME, false); super.onStart(); final IntentFilter filter = new IntentFilter(BROADCAST_USER_LIST_DETAILS_UPDATED); filter.addAction(BROADCAST_USER_LIST_SUBSCRIPTION_CHANGED); registerReceiver(mStatusReceiver, filter); }