Example usage for android.content IntentFilter addAction

List of usage examples for android.content IntentFilter addAction

Introduction

In this page you can find the example usage for android.content IntentFilter addAction.

Prototype

public final void addAction(String action) 

Source Link

Document

Add a new Intent action to match against.

Usage

From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java

@Override
protected void onResume() {
    super.onResume();
    if (broadcastManager == null) {
        broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
    }/*from ww w  .  j  ava 2 s .  c om*/
    if (receiver == null) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Keys.ACTION_LOGINSTATUSSUCCESS);
        filter.addAction(Keys.ACTION_LOGINSTATUSFAILURE);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        receiver = new StatusReceiver();
        broadcastManager.registerReceiver(receiver, filter);
    }
}

From source file:com.polyvi.xface.extension.XAppExt.java

private void registerInstallerReceiver(final XCallbackContext callbackCtx) {
    if (null == mInstallerReceiver) {
        mInstallerReceiver = new BroadcastReceiver() {
            @Override/* w w w  .  ja  v a  2s. c  o  m*/
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")
                        && (uninstallPackageName.equals(intent.getDataString().substring(8)))) {
                    XExtensionResult result = new XExtensionResult(XExtensionResult.Status.OK);
                    callbackCtx.sendExtensionResult(result);
                }
                if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
                    XExtensionResult result = new XExtensionResult(XExtensionResult.Status.OK);
                    callbackCtx.sendExtensionResult(result);
                }
            }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addDataScheme("package");
        getContext().registerReceiver(mInstallerReceiver, filter);
    }
}

From source file:com.cyanogenmod.eleven.ui.fragments.QueueFragment.java

@Override
public void onStart() {
    super.onStart();

    final IntentFilter filter = new IntentFilter();
    // Play and pause changes
    filter.addAction(MusicPlaybackService.PLAYSTATE_CHANGED);
    // Queue changes
    filter.addAction(MusicPlaybackService.QUEUE_CHANGED);
    // Track changes
    filter.addAction(MusicPlaybackService.META_CHANGED);

    getActivity().registerReceiver(mQueueUpdateListener, filter);

    // resume the progress listeners
    setPlayPauseProgressButtonStates(false);
}

From source file:com.lullabot.android.apps.iosched.ui.SessionDetailFragment.java

@Override
public void onResume() {
    super.onResume();

    // Start listening for time updates to adjust "now" bar. TIME_TICK is
    // triggered once per minute, which is how we move the bar over time.
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    getActivity().registerReceiver(mPackageChangesReceiver, filter);
}

From source file:com.cypress.cysmart.HomePageActivity.java

@Override
protected void onResume() {
    mApplicationInBackground = false;//from   w  w  w.  ja v a  2s.  com
    BLUETOOTH_STATUS_FLAG = true;
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(mBondStateReceiver, intentFilter);
    super.onResume();
}

From source file:com.auth0.android.lock.Lock.java

private void initialize(Activity activity) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.AUTHENTICATION_ACTION);
    filter.addAction(Constants.SIGN_UP_ACTION);
    filter.addAction(Constants.CANCELED_ACTION);
    filter.addAction(Constants.INVALID_CONFIGURATION_ACTION);
    LocalBroadcastManager.getInstance(activity).registerReceiver(this.receiver, filter);
}

From source file:com.poinsart.votar.VotarMain.java

@Override
protected void onResume() {
    super.onResume();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    registerReceiver(broadcastReceiver, intentFilter);
    updateWifiStatus();//from  ww w  . ja  va2s  . com
}

From source file:com.cyanogenmod.eleven.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}//from ww w .  j  a  va2 s . c om
 */
@Override
protected void onStart() {
    super.onStart();
    final IntentFilter filter = new IntentFilter();
    // Play and pause changes
    filter.addAction(MusicPlaybackService.PLAYSTATE_CHANGED);
    // Track changes
    filter.addAction(MusicPlaybackService.META_CHANGED);
    // Update a list, probably the playlist fragment's
    filter.addAction(MusicPlaybackService.REFRESH);
    // If a playlist has changed, notify us
    filter.addAction(MusicPlaybackService.PLAYLIST_CHANGED);
    // If there is an error playing a track
    filter.addAction(MusicPlaybackService.TRACK_ERROR);
    registerReceiver(mPlaybackStatus, filter);

    mPlayPauseProgressButton.resume();
}

From source file:com.javadog.bluetoothproximitylock.BluetoothFragment.java

/**
 * Initializes object references and performs some other set-up tasks.
 */// w w w. j av  a 2  s  . com
private void initialize() {
    //Get a reference to the user preferences editor
    userPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());

    //Get fresh references to our views
    serviceToggle = new BetterCompoundButton<>(getActivity(),
            (Switch) getView().findViewById(R.id.button_bt_service_start_stop));
    signalStrengthView = (TextView) getView().findViewById(R.id.bt_signal_strength);
    deviceChooser = (Spinner) getView().findViewById(R.id.bt_device_chooser);
    lockDistance = (Spinner) getView().findViewById(R.id.bt_lock_distances); //TODO: This doesn't do anything yet.
    lockInstantly = new BetterCompoundButton<>(getActivity(),
            (CheckBox) getView().findViewById(R.id.bt_lock_instantly));
    refreshIntervalSpinner = (Spinner) getView().findViewById(R.id.bt_refresh_interval);

    //Get a reference to the local broadcast manager, and specify which intent actions we want to listen for
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity().getApplicationContext());
    IntentFilter filter = new IntentFilter();
    filter.addAction(SignalReaderService.ACTION_SIGNAL_STRENGTH_UPDATE);
    filter.addAction(SignalReaderService.ACTION_UNBIND_SERVICE);

    //Instantiate the ssReceiver if it's not already, then register it with the broadcast manager
    if (ssReceiver == null) {
        ssReceiver = new LocalBroadcastReceiver();
    }
    manager.registerReceiver(ssReceiver, filter);

    //Check whether device admin privileges are active, and show a dialog if not
    DevicePolicyManager dpm = (DevicePolicyManager) getActivity()
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!dpm.isAdminActive(new ComponentName(getActivity().getApplicationContext(), DeviceLockManager.class))) {
        AdminDialogFragment adminDialogFragment = new AdminDialogFragment();
        adminDialogFragment.setCancelable(false);
        adminDialogFragment.show(getFragmentManager(), "needsAdmin");
    }

    populateBtDevices();

    //Start the device chooser in a disabled state if Bluetooth is disabled
    if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        deviceChooser.setEnabled(true);
    } else {
        deviceChooser.setEnabled(false);
    }

    //Register a listener with the system to get updates about changes to Bluetooth state
    if (btStateReceiver == null) {
        btStateReceiver = new BluetoothStateReceiver();
    }
    IntentFilter btFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    getActivity().registerReceiver(btStateReceiver, btFilter);

    /**
     * Will attach the Activity to the Service as soon as the service is started.
     */
    serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            serviceBound = true;
            updateBtServiceUI();
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            //This should never be called because our service resides in the same process.
        }
    };
}

From source file:name.gumartinm.weather.information.fragment.current.CurrentFragment.java

@Override
public void onResume() {
    super.onResume();

    this.mReceiver = new BroadcastReceiver() {

        @Override/*from   w ww  . j  a v a 2  s .c  om*/
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (action.equals(BROADCAST_INTENT_ACTION)) {
                final Current currentRemote = (Current) intent.getSerializableExtra("current");

                // 1. Check conditions. They must be the same as the ones that triggered the AsyncTask.
                final DatabaseQueries query = new DatabaseQueries(context.getApplicationContext());
                final WeatherLocation weatherLocation = query.queryDataBase();
                final PermanentStorage store = new PermanentStorage(context.getApplicationContext());
                final Current current = store.getCurrent();

                if (current == null
                        || !CurrentFragment.this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) {

                    if (currentRemote != null) {
                        // 2. Update UI.
                        CurrentFragment.this.updateUI(currentRemote);

                        // 3. Update current data.
                        store.saveCurrent(currentRemote);

                        // 4. Update location data.
                        weatherLocation.setLastCurrentUIUpdate(new Date());
                        query.updateDataBase(weatherLocation);
                    } else {
                        // Empty UI and show error message
                        CurrentFragment.this.getActivity().findViewById(R.id.weather_current_data_container)
                                .setVisibility(View.GONE);
                        CurrentFragment.this.getActivity().findViewById(R.id.weather_current_progressbar)
                                .setVisibility(View.GONE);
                        CurrentFragment.this.getActivity().findViewById(R.id.weather_current_error_message)
                                .setVisibility(View.VISIBLE);
                    }
                }
            }
        }
    };

    // Register receiver
    final IntentFilter filter = new IntentFilter();
    filter.addAction(BROADCAST_INTENT_ACTION);
    LocalBroadcastManager.getInstance(this.getActivity().getApplicationContext())
            .registerReceiver(this.mReceiver, filter);

    // Empty UI
    this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.GONE);

    final DatabaseQueries query = new DatabaseQueries(this.getActivity().getApplicationContext());
    final WeatherLocation weatherLocation = query.queryDataBase();
    if (weatherLocation == null) {
        // Nothing to do.
        // Show error message
        final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar);
        progress.setVisibility(View.GONE);
        final TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message);
        errorMessage.setVisibility(View.VISIBLE);
        return;
    }

    // If is new location update widgets.
    if (weatherLocation.getIsNew()) {
        WidgetProvider.refreshAllAppWidgets(this.getActivity().getApplicationContext());
        // Update location data.
        weatherLocation.setIsNew(false);
        query.updateDataBase(weatherLocation);
    }

    final PermanentStorage store = new PermanentStorage(this.getActivity().getApplicationContext());
    final Current current = store.getCurrent();

    if (current != null && this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) {
        this.updateUI(current);
    } else {
        // Load remote data (asynchronous)
        // Gets the data from the web.
        this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.VISIBLE);
        this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE);
        final CurrentTask task = new CurrentTask(this.getActivity().getApplicationContext(),
                new CustomHTTPClient(AndroidHttpClient.newInstance(this.getString(R.string.http_client_agent))),
                new ServiceCurrentParser(new JPOSCurrentParser()));

        task.execute(weatherLocation.getLatitude(), weatherLocation.getLongitude());
    }
}