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:cc.arduino.mvd.services.BinocularService.java

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

    IntentFilter filter = new IntentFilter();
    filter.addAction(MvdHelper.ACTION_UP);
    filter.addAction(MvdHelper.ACTION_DOWN);
    filter.addAction(MvdHelper.ACTION_KILL);

    registerReceiver(broadcastReceiver, filter);
}

From source file:audio.lisn.service.MediaNotificationManager.java

/**
 * Posts the notification and starts tracking the session to keep it
 * updated. The notification will automatically be removed if the session is
 * destroyed before {@link #stopNotification} is called.
 *///from   w w  w  .  j  a  v  a  2  s  .c  o m
public void startNotification() {
    if (!mStarted) {

        // mNotificationManager.cancel(NOTIFICATION_ID);

        //        if(mStarted){
        //            stopNotification();
        //        }
        //if (!mStarted) {
        // mMetadata = mController.getMetadata();
        // mPlaybackState = mController.getPlaybackState();

        // The notification must be updated after setting started to true
        Notification notification = createNotification();
        if (notification != null) {
            // mController.registerCallback(mCb);
            IntentFilter filter = new IntentFilter();
            filter.addAction(ACTION_NEXT);
            filter.addAction(ACTION_PAUSE);
            filter.addAction(ACTION_PLAY);
            filter.addAction(ACTION_PREV);
            filter.addAction(ACTION_DELETE);
            mService.registerReceiver(this, filter);

            mService.startForeground(NOTIFICATION_ID, notification);
            mStarted = true;
        }
    } else {
        mService.stopForeground(true);

        Notification notification = createNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}

From source file:com.github.opengarageapp.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction(GarageToggleService.INTENT_CLOSE1);
    filter.addAction(GarageToggleService.INTENT_TOGGLE1);
    filter.addAction(GarageToggleService.INTENT_ERROR);
    filter.addAction(GarageToggleService.INTENT_STATE1);
    filter.addAction(GarageToggleService.INTENT_CLOSE2);
    filter.addAction(GarageToggleService.INTENT_TOGGLE2);
    filter.addAction(GarageToggleService.INTENT_ERROR);
    filter.addAction(GarageToggleService.INTENT_STATE2);
    registerReceiver(receiver, filter);/*from w ww.j ava 2 s .  co m*/
    // Start up the getState loop.
    if (application.getSelectedAccount() != null) {
        startStateLoop();
    }
    // If the actvitiy was closed before the previous service started, the
    // buttons
    // will still be in a disabled state. Re-enable them here.
    if (!isServiceRunning(GarageToggleService.class.getName())) {
        enableButtons1(true);
        enableButtons2(true);
    }
}

From source file:name.gumartinm.weather.information.fragment.overview.OverviewFragment.java

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

    this.mReceiver = new BroadcastReceiver() {

        @Override//from   w  ww  .  ja va 2 s. c  o  m
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (action.equals(BROADCAST_INTENT_ACTION)) {
                final Forecast forecastRemote = (Forecast) intent.getSerializableExtra("forecast");

                // 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 Forecast forecast = store.getForecast();

                if (forecast == null
                        || !OverviewFragment.this.isDataFresh(weatherLocation.getLastForecastUIUpdate())) {

                    if (forecastRemote != null) {
                        // 2. Update UI.
                        OverviewFragment.this.updateUI(forecastRemote);

                        // 3. Update Data.
                        store.saveForecast(forecastRemote);
                        weatherLocation.setLastForecastUIUpdate(new Date());
                        query.updateDataBase(weatherLocation);

                        // 4. Show list.
                        OverviewFragment.this.setListShownNoAnimation(true);
                    } else {
                        // Empty list and show error message (see setEmptyText in onCreate)
                        OverviewFragment.this.setListAdapter(null);
                        OverviewFragment.this.setListShownNoAnimation(true);
                    }
                }
            }
        }
    };

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

    final DatabaseQueries query = new DatabaseQueries(this.getActivity().getApplicationContext());
    final WeatherLocation weatherLocation = query.queryDataBase();
    if (weatherLocation == null) {
        // Nothing to do.
        // Empty list and show error message (see setEmptyText in onCreate)
        this.setListAdapter(null);
        this.setListShownNoAnimation(true);
        return;
    }

    final PermanentStorage store = new PermanentStorage(this.getActivity().getApplicationContext());
    final Forecast forecast = store.getForecast();

    if (forecast != null && this.isDataFresh(weatherLocation.getLastForecastUIUpdate())) {
        this.updateUI(forecast);
    } else {
        // Load remote data (aynchronous)
        // Gets the data from the web.
        this.setListShownNoAnimation(false);
        final OverviewTask task = new OverviewTask(this.getActivity().getApplicationContext(),
                new CustomHTTPClient(AndroidHttpClient.newInstance(this.getString(R.string.http_client_agent))),
                new ServiceForecastParser(new JPOSForecastParser()));

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

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java

@Override
public void onCreate() {
    super.onCreate();
    // Use filter for Monitor Significant Changes in Battery Level only
    // Generally speaking, the impact of constantly monitoring the
    // battery//from   ww w.  j  ava  2 s  . c o  m
    // level has a greater impact on the battery than your app's normal
    // behavior, so it's good practice to only monitor significant
    // changes
    // in battery levelspecifically when the device enters or exits a
    // low
    // battery state.
    IntentFilter ifilter = new IntentFilter();
    ifilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    // ifilter.addAction(Intent.ACTION_BATTERY_OKAY);
    this.registerReceiver(batteryLvlReceiver, ifilter);

    // get Location
    MyLocation myLocation = new MyLocation();
    myLocation.getLocation(this, locationResult);

    // scheduleNextUpdate();

    // Notify user of this service
    //      systemNotice();

    this.stopSelf();

}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuService.java

private static IntentFilter makeDfuActionIntentFilter() {
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(DfuService.BROADCAST_ACTION);
    return intentFilter;
}

From source file:com.linkbubble.MainService.java

@Override
public void onCreate() {

    mDestroyAllActivities = true;/* w ww.j  av a 2  s.c om*/
    mRestoreComplete = false;

    setTheme(Settings.get().getDarkThemeEnabled() ? R.style.MainServiceThemeDark
            : R.style.MainServiceThemeLight);

    super.onCreate();
    Fabric.with(this, new Crashlytics());
    CrashTracking.log("MainService.onCreate()");

    showDefaultNotification();

    Config.init(this);
    Settings.get().onOrientationChange();

    try {
        WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
    } catch (RuntimeException exc) {
        CrashTracking.logHandledException(exc);
    }

    MainApplication.mDestroyActivitySharedLock = new Object();
    MainApplication.mActivityDestroyed = false;

    MainController.create(this, new MainController.EventHandler() {
        @Override
        public void onDestroy() {
            Settings.get().saveBubbleRestingPoint();
            stopSelf();
            CrashTracking.log("MainService.onCreate(): onDestroy()");
        }
    });

    //Intent i = new Intent();
    //i.setData(Uri.parse("https://t.co/uxMl3bWtMP"));
    //i.setData(Uri.parse("http://t.co/oOyu7GBZMU"));
    //i.setData(Uri.parse("http://goo.gl/abc57"));
    //i.setData(Uri.parse("https://bitly.com/QtQET"));
    //i.setData(Uri.parse("http://www.duckduckgo.com"));
    //openUrl("https://www.duckduckgo.com");
    //openUrl("http://www.duckduckgo.com", true);
    //openUrl("https://t.co/uxMl3bWtMP", true);

    IntentFilter filter = new IntentFilter();
    filter.addAction(BCAST_CONFIGCHANGED);
    registerReceiver(mBroadcastReceiver, filter);

    registerReceiver(mDialogReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");

    filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mScreenReceiver, filter);

    MainApplication.registerForBus(this, this);
}

From source file:com.firefly.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

@Override
public void onCreate() {
    super.onCreate();
    LOGD(TAG, "onCreate()");
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    mBroadcastReceiver = new BroadcastReceiver() {

        @Override//from w  w  w .  j  a va  2 s .  com
        public void onReceive(Context context, Intent intent) {
            LOGD(TAG, "onReceive(): " + intent.getAction());
        }
    };

    registerReceiver(mBroadcastReceiver, filter);

    readPersistedData();
    mCastManager = VideoCastManager.initialize(this, mApplicationId, mTargetActivity, mDataNamespace);
    if (!mCastManager.isConnected()) {
        mCastManager.reconnectSessionIfPossible(this, false);
    }
    mConsumer = new VideoCastConsumerImpl() {
        @Override
        public void onApplicationDisconnected(int errorCode) {
            LOGD(TAG, "onApplicationDisconnected() was reached");
            stopSelf();
        }

        @Override
        public void onRemoteMediaPlayerStatusUpdated() {
            int mediaStatus = mCastManager.getPlaybackStatus();
            VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus);
        }

    };
    mCastManager.addVideoCastConsumer(mConsumer);
}

From source file:com.omt.syncpad.DemoKitActivity.java

/** Called when the activity is first created. */
@Override//w ww .j  av  a2  s. com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUsbManager = UsbManager.getInstance(this);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);
    }

    setContentView(R.layout.main);

    enableControls(false);
}