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.android.madpausa.cardnotificationviewer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (sp.getBoolean(SettingsActivityFragment.TEST_MODE, false))
        setContentView(R.layout.activity_main_test);
    else/*w  w  w  .  j a  v  a  2 s .  co m*/
        setContentView(R.layout.activity_main);

    //binding the service
    Intent intent = new Intent(this, ConcreteNotificationListenerService.class);
    intent.setAction(ConcreteNotificationListenerService.CUSTOM_BINDING);
    bindService(intent, nConnection, Context.BIND_AUTO_CREATE);
    nReceiver = new NotificationReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConcreteNotificationListenerService.ADD_NOTIFICATION_ACTION);
    filter.addAction(ConcreteNotificationListenerService.REMOVE_NOTIFICATION_ACTION);
    filter.addAction(NotificationDialogFragment.NOTIFICATION_DIALOG_INTENT);
    LocalBroadcastManager.getInstance(this).registerReceiver(nReceiver, filter);
    nFragment = (MainActivityFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);

}

From source file:com.javadog.cgeowear.CompassActivity.java

private void listenForUpdates() {
    localBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
    IntentFilter updateFilter = new IntentFilter();
    updateFilter.addAction(ACTION_TRIGGER_MINIMAL_REFRESH);
    updateFilter.addAction(ListenerService.PATH_KILL_APP);
    localBroadcastManager.registerReceiver(localBroadcastReceiver, updateFilter);
}

From source file:com.adam.aslfms.SettingsActivity.java

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

    checkNetwork();/*from  w  w  w . ja  va2s . c  om*/

    IntentFilter ifs = new IntentFilter();
    ifs.addAction(ScrobblingService.BROADCAST_ONSTATUSCHANGED);
    registerReceiver(onStatusChange, ifs);
    update();
}

From source file:com.lendingtree.view.BaseActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
    this.registerReceiver(this.receiver, filter);
}

From source file:com.andreadec.musicplayer.PodcastEpisodeDownloaderService.java

@Override
protected void onHandleIntent(Intent intent) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(STOP_DOWNLOAD_INTENT);
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override/*w  ww  . jav a  2  s  . c o m*/
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(STOP_DOWNLOAD_INTENT)) {
                downloadInProgress = false;
            }
        }
    };
    registerReceiver(broadcastReceiver, intentFilter);

    String type = intent.getStringExtra("type");
    String title = intent.getStringExtra("title");
    String idItem = intent.getStringExtra("idItem");
    String podcastsDirectory = intent.getStringExtra("podcastsDirectory");
    notificationBuilder.setContentTitle(getResources().getString(R.string.podcastDownloading, title));
    notificationBuilder.setContentText(getResources().getString(R.string.podcastDownloading, title));
    notificationManager.notify(Constants.NOTIFICATION_PODCAST_ITEM_DOWNLOAD_ONGOING,
            notificationBuilder.build());

    String filename;
    do {
        filename = podcastsDirectory + "/" + UUID.randomUUID().toString();
    } while (new File(filename).exists()); // To avoid accidentally override an already existing file
    Intent intentCompleted = new Intent("com.andreadec.musicplayer.podcastdownloadcompleted");

    HttpURLConnection httpConnection = null;

    try {
        if (type.equalsIgnoreCase("audio/mpeg") || type.equalsIgnoreCase("audio/.mp3"))
            filename += ".mp3";
        else if (type.equalsIgnoreCase("audio/ogg"))
            filename += ".ogg";
        else
            throw new Exception("Unsupported format");

        URL url = new URL(intent.getStringExtra("url"));
        httpConnection = (HttpURLConnection) url.openConnection();
        if (httpConnection.getResponseCode() != 200)
            throw new Exception("Failed to connect");
        length = httpConnection.getContentLength();
        lengthString = Utils.formatFileSize(length);
        input = httpConnection.getInputStream();
        output = new FileOutputStream(filename);

        byte[] buffer = new byte[1024];
        int read = 0;
        totalRead = 0;
        downloadInProgress = true;
        new NotificationThread().start();
        while ((read = input.read(buffer)) > 0) {
            if (!downloadInProgress) {
                input.close();
                throw new Exception();
            }
            output.write(buffer, 0, read);
            totalRead += read;
        }

        intentCompleted.putExtra("success", true);
        PodcastEpisode.setDownloadedFile(idItem, filename);

        output.flush();
        output.close();
    } catch (Exception e) {
        new File(filename).delete();
        PodcastEpisode.setDownloadCanceled(idItem);
        intentCompleted.putExtra("success", false);
        intentCompleted.putExtra("reason", e.getMessage());
        showErrorNotification(e.getMessage());
    } finally {
        try {
            httpConnection.disconnect();
        } catch (Exception e) {
        }
    }

    downloadInProgress = false;
    unregisterReceiver(broadcastReceiver);

    sendBroadcast(intentCompleted);
    notificationManager.cancel(Constants.NOTIFICATION_PODCAST_ITEM_DOWNLOAD_ONGOING);
}

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

/**
 * ? plugin  NetworkConnection ./*  ww  w. ja  va2s  .  com*/
 *  Android ??BroadcastReceiver Android  broadcast
 *
 */
public void initConnectionContext() {
    Context context = getContext();
    this.mSockMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // ????connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.mReceiver == null) {
        this.mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                updateConnectionInfo(
                        (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
            }
        };
        context.registerReceiver(this.mReceiver, intentFilter);
    }
}

From source file:com.lukekorth.ez_loaders.EzLoader.java

@Override
protected void onStartLoading() {
    if (mT != null) {
        // Deliver any previously loaded data immediately.
        deliverResult(mT);//from   ww w .ja  v a  2  s.  c o m
    }

    // Register the BroadcastReceiver that will notify the Loader when changes are
    // made.
    if (mBroadcastReceiver == null) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(mBroadcastAction);

        mBroadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onContentChanged();
            }
        };

        if (mUseLocalBroadcastManager) {
            LocalBroadcastManager.getInstance(getContext()).registerReceiver(mBroadcastReceiver, filter);
        } else {
            getContext().registerReceiver(mBroadcastReceiver, filter);
        }
    }

    if (takeContentChanged()) {
        // When the observer detects new data, it will call
        // onContentChanged() on the Loader, which will cause the next call
        // to takeContentChanged() to return true. If this is ever the case
        // (or if the current data is null), we force a new load.
        forceLoad();
    } else if (mT == null) {
        // If the current data is null... then we should make it non-null
        forceLoad();
    }
}

From source file:com.android.example.notificationlistener.Listener.java

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "registering broadcast listener");
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ACTION_DISMISS);
    intentFilter.addAction(ACTION_LAUNCH);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
}

From source file:com.google.samples.apps.friendlyping.fragment.FriendlyPingFragment.java

@Override
public void onResume() {
    super.onResume();
    final IntentFilter filter = new IntentFilter();
    filter.addAction(RegistrationConstants.REGISTRATION_COMPLETE);
    filter.addAction(GcmAction.SEND_CLIENT_LIST);
    filter.addAction(GcmAction.BROADCAST_NEW_CLIENT);
    filter.addAction(GcmAction.PING_CLIENT);
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mRegistrationBroadcastReceiver, filter);
}

From source file:com.linkedin.android.shaky.Shaky.java

Shaky(@NonNull Context context, @NonNull ShakeDelegate delegate) {
    Context appContext = context.getApplicationContext();
    this.delegate = delegate;
    shakeDetector = new ShakeDetector(this);

    shakeDetector.setSensitivity(getDetectorSensitivityLevel());

    IntentFilter filter = new IntentFilter();
    filter.addAction(SendFeedbackDialog.ACTION_START_FEEDBACK_FLOW);
    filter.addAction(FeedbackActivity.ACTION_END_FEEDBACK_FLOW);
    LocalBroadcastManager.getInstance(appContext).registerReceiver(createReceiver(), filter);
}