List of usage examples for android.content IntentFilter IntentFilter
public IntentFilter(Parcel source)
From source file:com.commontime.plugin.LocationManager.java
private void initBluetoothListener() { //check access if (!hasBlueToothPermission()) { debugWarn("Cannot listen to Bluetooth service when BLUETOOTH permission is not added"); return;/* w w w. j av a 2 s .c om*/ } //check device support try { iBeaconManager.checkAvailability(); } catch (Exception e) { //if device does not support iBeacons an error is thrown debugWarn("Cannot listen to Bluetooth service: " + e.getMessage()); return; } if (broadcastReceiver != null) { debugWarn("Already listening to Bluetooth service, not adding again"); return; } broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); // Only listen for Bluetooth server changes if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BluetoothAdapter.ERROR); debugLog("Bluetooth Service state changed from " + getStateDescription(oldState) + " to " + getStateDescription(state)); switch (state) { case BluetoothAdapter.ERROR: beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusNotDetermined"); break; case BluetoothAdapter.STATE_OFF: case BluetoothAdapter.STATE_TURNING_OFF: if (oldState == BluetoothAdapter.STATE_ON) beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusDenied"); break; case BluetoothAdapter.STATE_ON: beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusAuthorized"); break; case BluetoothAdapter.STATE_TURNING_ON: break; } } } private String getStateDescription(int state) { switch (state) { case BluetoothAdapter.ERROR: return "ERROR"; case BluetoothAdapter.STATE_OFF: return "STATE_OFF"; case BluetoothAdapter.STATE_TURNING_OFF: return "STATE_TURNING_OFF"; case BluetoothAdapter.STATE_ON: return "STATE_ON"; case BluetoothAdapter.STATE_TURNING_ON: return "STATE_TURNING_ON"; } return "ERROR" + state; } }; // Register for broadcasts on BluetoothAdapter state change IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); cordova.getActivity().registerReceiver(broadcastReceiver, filter); }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
public void initDownloadComponents() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override/* www . jav a2 s.c o m*/ public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { // } } }; context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); context.unregisterReceiver(receiver); }
From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java
private void waitForPageLoaded(Bundle savedInstanceState) { final String savedHash = savedInstanceState != null ? savedInstanceState.getString(EXTRA_SAVED_ATTACHMENTHASH) : null;/* w w w .j av a2 s . c o m*/ if (savedHash != null) registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction() != null && intent.getAction().equals(BoardFragment.BROADCAST_PAGE_LOADED)) { unregisterReceiver(this); broadcastReceiver = null; Intent activityIntent = getIntent(); String pagehash = activityIntent.getStringExtra(EXTRA_PAGEHASH); if (pagehash != null && remote.isPageLoaded(pagehash)) { startActivity(activityIntent.putExtra(EXTRA_SAVED_ATTACHMENTHASH, savedHash)); finish(); } } } }, new IntentFilter(BoardFragment.BROADCAST_PAGE_LOADED)); }
From source file:net.helff.wificonnector.WifiConnectivityService.java
protected LoginToken waitForToken() throws ConnectionWorkflowException { LoginToken loginToken = new LoginToken(); // set up broadcast receiver publishProgress(getString(R.string.wifi_submit_msisdn), getString(R.string.wifi_wait_token), STATUS_WORKING, true);//from w w w .j a v a 2 s. com SMSReceiver receiver = new SMSReceiver(loginToken); IntentFilter intentFilter = new IntentFilter(SMSReceiver.ACTION); intentFilter.setPriority(smsPriority); registerReceiver(receiver, intentFilter); int iterations = 1; // loop every 500ms and wait for SMS arriving while (iterations < (smsDelay * 2) && !loginToken.isTokenSet()) { // just wait, therefore sleep a half second try { Thread.sleep(500); } catch (InterruptedException e) { // just finish then break; } iterations++; } // remove broadcast receiver unregisterReceiver(receiver); if (loginToken.isTokenSet()) { publishProgress(getString(R.string.wifi_submit_msisdn), getString(R.string.wifi_received_token, loginToken.getToken()), STATUS_WORKING); } else { publishProgress(getString(R.string.wifi_submit_msisdn), getString(R.string.wifi_no_token), STATUS_LOCKED, true); throw new ConnectionWorkflowException("no token received within 15 seconds"); } return loginToken; }
From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java
private void registerBroadcastReceivers() { getActivity().registerReceiver(cardInsertedReceiver, new IntentFilter(ACS.CARD_PRESENT_INTENT)); getActivity().registerReceiver(cardRemovedReceiver, new IntentFilter(ACS.CARD_ABSENT_INTENT)); getActivity().registerReceiver(connectivityBroadcastReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mobileIdBroadcastReceiver, new IntentFilter(MID_BROADCAST_ACTION)); }
From source file:fr.bmartel.android.tictactoe.GameSingleton.java
public void onResume() { LocalBroadcastManager.getInstance(context).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE)); activityForeground = true;/*from w w w . j a v a 2 s . c o m*/ }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java
/** * Request MFPPush to deliver incoming push messages to listener.onReceive() * method./* w w w . j ava2 s . c o m*/ * <p/> * This method is typically called from the onResume() method of the * activity that is handling push notifications. * * @param notificationListener MFPPushNotificationListener object whose onReceive() method * will be called upon receipt of a push message. */ public void listen(MFPPushNotificationListener notificationListener) { if (!onMessageReceiverRegistered) { appContext.registerReceiver(onMessage, new IntentFilter(getIntentPrefix(appContext) + GCM_MESSAGE)); onMessageReceiverRegistered = true; this.notificationListener = notificationListener; setAppForeground(true); boolean gotSavedMessages; if (pushNotificationIntent != null) { gotSavedMessages = getMessagesFromSharedPreferences( pushNotificationIntent.getIntExtra("notificationId", 0)); } else { gotSavedMessages = getMessagesFromSharedPreferences(0); } if (!isFromNotificationBar) { if (gotSavedMessages) { dispatchPending(); } cancelAllNotification(); } else { if (messageFromBar != null) { isFromNotificationBar = false; notificationListener.onReceive(new MFPSimplePushNotification(messageFromBar)); relayNotificationSync(messageFromBar.getKey(), messageFromBar.getId()); messageFromBar = null; } } } else { logger.info("MFPPush:listen() - onMessage broadcast listener has already been registered."); } }
From source file:com.ubuntuone.android.files.service.UpDownService.java
private void registerDownloadCancelReceiver() { LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this); downloadCancelReceiver = new BroadcastReceiver() { @Override/*from w ww . j av a 2 s. c om*/ public void onReceive(Context context, Intent intent) { if (downloadCancelTrigger != null) { downloadCancelTrigger.onCancel(); } Uri uri = intent.getData(); if (uri == null) { // Cancel all downloads. uri = Downloads.CONTENT_URI; } TransferUtils.dequeue(contentResolver, uri); } }; IntentFilter filter = new IntentFilter(ACTION_CANCEL_DOWNLOAD); IntentFilter filterId = null; try { filterId = new IntentFilter(ACTION_CANCEL_DOWNLOAD, "*/*"); } catch (MalformedMimeTypeException e) { // Not interested. } bm.registerReceiver(downloadCancelReceiver, filter); if (filterId != null) { bm.registerReceiver(downloadCancelReceiver, filterId); } }
From source file:com.hypodiabetic.happ.MainActivity.java
public void checkInsulinAppIntegration(View view) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstace()); Date now = new Date(); Profile p = new Profile(now, MainActivity.getInstace()); //Local device based Integrations String insulin_Integration_App = prefs.getString("insulin_integration", ""); //Insulin Integration App, try and connect if (!insulin_Integration_App.equals("")) { final InsulinIntegrationApp insulinIntegrationApp = new InsulinIntegrationApp(MainActivity.getInstace(), insulin_Integration_App, "TEST"); insulinIntegrationApp.connectInsulinTreatmentApp(); insulinIntegrationApp_status.setText("Connecting..."); insulinIntegrationApp_icon.setBackground(clockWhite); insulinIntegrationApp_icon.setColorFilter(Color.WHITE); //listens out for connection insulinIntegrationAppUpdate = new BroadcastReceiver() { @Override//from w w w . ja v a 2 s . c om public void onReceive(Context context, Intent intent) { insulinIntegrationApp_status.setText(intent.getStringExtra("MSG")); insulinIntegrationApp_icon.setBackground(tickWhite); insulinIntegrationApp.sendTest(); LocalBroadcastManager.getInstance(MainActivity.getInstace()) .unregisterReceiver(insulinIntegrationAppUpdate); } }; LocalBroadcastManager.getInstance(MainActivity.getInstace()) .registerReceiver(insulinIntegrationAppUpdate, new IntentFilter("INSULIN_INTEGRATION_TEST")); } else { insulinIntegrationApp_status.setText("No app selected or not in Closed Loop"); insulinIntegrationApp_icon.setBackgroundResource(R.drawable.alert_circle); } }
From source file:org.csp.everyaware.offline.Map.java
@Override public void onResume() { Utils.paused = false;//from w ww . j ava 2 s .co m super.onResume(); mMapView.onResume(); //acquire partial wake lock if (!mWakeLock.isHeld()) mWakeLock.acquire(); mLocationSource.registerLocUpdates(); if (Utils.uploadOn == Constants.INTERNET_ON_INT) mInterUplStatus.setBackgroundResource(R.drawable.internet_on); else if (Utils.uploadOn == Constants.INTERNET_OFF_INT) mInterUplStatus.setBackgroundResource(R.drawable.internet_off); else if (Utils.uploadOn == Constants.UPLOAD_ON_INT) mInterUplStatus.setBackgroundResource(R.drawable.upload); if (mCameraTrackOn) mFollowCamBtn.setBackgroundResource(R.drawable.follow_camera_pressed); else mFollowCamBtn.setBackgroundResource(R.drawable.follow_camera_not_pressed); //register receiver for messages from store'n'forward service IntentFilter internetOnFilter = new IntentFilter(Constants.INTERNET_ON); registerReceiver(mServiceReceiver, internetOnFilter); IntentFilter internetOffFilter = new IntentFilter(Constants.INTERNET_OFF); registerReceiver(mServiceReceiver, internetOffFilter); IntentFilter uploadOnFilter = new IntentFilter(Constants.UPLOAD_ON); registerReceiver(mServiceReceiver, uploadOnFilter); IntentFilter uploadOffFilter = new IntentFilter(Constants.UPLOAD_OFF); registerReceiver(mServiceReceiver, uploadOffFilter); //register receiver for messages from gps tracking service IntentFilter phoneGpsOnFilter = new IntentFilter(Constants.PHONE_GPS_ON); registerReceiver(mGpsServiceReceiver, phoneGpsOnFilter); IntentFilter networkGpsOnFilter = new IntentFilter(Constants.NETWORK_GPS_ON); registerReceiver(mGpsServiceReceiver, networkGpsOnFilter); IntentFilter phoneGpsOffFilter = new IntentFilter(Constants.PHONE_GPS_OFF); registerReceiver(mGpsServiceReceiver, phoneGpsOffFilter); //get selected track and draw it on map mTrack = Utils.track; if (mTrack != null) { Log.d("Map", "onCreate()--> shown session id: " + mTrack.mSessionId); if (mGoogleMap != null) mGoogleMap.clear(); int divider = 1; long trackLength = mTrack.mNumOfRecords; Log.d("Map", "onResume()--> track length: " + trackLength); if (trackLength > 1800) divider = 2; if (trackLength > 3600) divider = 4; if (trackLength > 7200) divider = 8; if (trackLength > 14400) divider = 16; mLatLngPoints = mDbManager.loadLatLngPointsBySessionId(mTrack.mSessionId, divider); if (mLatLngPoints != null) { int size = mLatLngPoints.size(); if (size > 0) { calcMinAvgPollValue(); drawPath(); mCameraTrackOn = false; if (mGoogleMap != null) try { mGoogleMap.animateCamera( CameraUpdateFactory.newLatLng(mLatLngPoints.get(size - 1).mLatLng)); } catch (NullPointerException e) { e.printStackTrace(); } } } } if (mMapPolygons == null) mMapPolygons = new ArrayList<Polygon>(); int color; //draw map cluster on the map if ((mMapClusters != null) && (mMapClusters.size() > 0)) { for (int i = 0; i < mMapClusters.size(); i++) { MapCluster mapCluster = mMapClusters.get(i); if (mapCluster.mBcLevel != 0) { if ((mapCluster.mBcLevel > 0) && (mapCluster.mBcLevel <= 10)) color = ColorHelper.numberToColor(mapCluster.mBcLevel * BC_MULTIPLIER); else color = ColorHelper.numberToColor(100); mMapPolygons.add(mGoogleMap.addPolygon(new PolygonOptions() .add(new LatLng(mapCluster.mMinLat, mapCluster.mMinLon), new LatLng(mapCluster.mMinLat, mapCluster.mMaxLon), new LatLng(mapCluster.mMaxLat, mapCluster.mMaxLon), new LatLng(mapCluster.mMaxLat, mapCluster.mMinLon)) .strokeColor(Color.TRANSPARENT) .fillColor(Color.parseColor("#66" + String.format("%06X", 0xFFFFFF & color))))); } } } }