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.nfc.gemkey.MainActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (DEBUG)//  w  w  w. j a va 2s .  co  m
        Log.d(TAG, "onCreate");
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
    mFilters = new IntentFilter[] { tagDetected };

    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    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) {
        Log.i(TAG, "open usb accessory@onCreate");
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);
    }

    buttonLED = (ToggleButton) findViewById(R.id.nfc_btn);
    buttonLED.setBackgroundResource(
            buttonLED.isChecked() ? R.drawable.btn_toggle_yes : R.drawable.btn_toggle_no);
    buttonLED.setOnCheckedChangeListener(mKeyLockListener);

    tagId = (TextView) findViewById(R.id.nfc_tag);
    tagId.setText(R.string.nfc_scan_tag);

    // Avoid NetworkOnMainThreadException
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

From source file:com.dwdesign.tweetings.fragment.DMConversationFragment.java

@Override
public void onStart() {
    super.onStart();
    final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED);
    filter.addAction(BROADCAST_RECEIVED_DIRECT_MESSAGES_DATABASE_UPDATED);
    filter.addAction(BROADCAST_SENT_DIRECT_MESSAGES_DATABASE_UPDATED);
    filter.addAction(BROADCAST_RECEIVED_DIRECT_MESSAGES_REFRESHED);
    filter.addAction(BROADCAST_SENT_DIRECT_MESSAGES_REFRESHED);
    registerReceiver(mStatusReceiver, filter);

    final float text_size = mPreferences.getFloat(PREFERENCE_KEY_TEXT_SIZE, PREFERENCE_DEFAULT_TEXT_SIZE);
    final boolean display_profile_image = mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true);
    final boolean display_name = mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_NAME, false);
    mAdapter.setDisplayProfileImage(display_profile_image);
    mAdapter.setDisplayName(display_name);
    mAdapter.setTextSize(text_size);/*from   www.  j  a  va2  s .  c  o m*/
}

From source file:hackathon.openrice.CardsActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Bundle extras = getIntent().getExtras();
    String keyword = null;// w  ww .  j a  v a  2 s .co  m
    if (extras != null) {
        ArrayList<String> text = extras.getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
        if (text != null) {
            for (String t : text) {
                String temp = t.toLowerCase().trim();
                if (temp.startsWith("search")) {
                    keyword = temp.substring(6).trim();
                }
            }
        }
    }
    Card info = new Card(this);
    info.setText("Loading data...");
    cards.add(info);
    RetrieveImage task = new RetrieveImage();

    // listener passed over to locationProvider, any location update is handled here
    this.locationListener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(final Location location) {
            // forward location updates fired by LocationProvider to architectView, you can set lat/lon from any location-strategy
            if (location != null) {
                // sore last location as member, in case it is needed somewhere (in e.g. your adjusted project)
                lastKnownLocation = location;
                if (lastKnownLocation != null) {
                    // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information)
                    if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) {
                        lastKnownLocation = location;
                    } else {
                        lastKnownLocation = location;
                    }
                }
            }
        }
    };
    locationProvider = new LocationProvider(this, locationListener);
    double x, y;
    if (lastKnownLocation != null) {
        x = lastKnownLocation.getLatitude();
        y = lastKnownLocation.getLongitude();
    } else {
        x = 22.3049989;
        y = 114.17925600000001;
    }
    if (keyword != null) {
        //Log.d("FFFF", keyword);
        task.execute(
                "http://openricescraper.herokuapp.com/?x=" + x + "&y=" + y + "&keyword=" + Uri.encode(keyword));
    } else {
        task.execute("http://openricescraper.herokuapp.com/?x=" + x + "&y=" + y);

    }
    mCardScroller = new CardScrollView(this);
    mCardScroller.setAdapter(new CardAdapter(cards));
    mCardScroller.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            final String className = "com.wikitude.samples.SampleCamActivity";

            try {

                final Intent intent = new Intent(ctx, Class.forName(className));
                intent.putExtra(EXTRAS_KEY_ACTIVITY_TITLE_STRING, "5.2 Adding Radar");
                intent.putExtra(EXTRAS_KEY_ACTIVITY_ARCHITECT_WORLD_URL,
                        "samples/5_Browsing$Pois_2_Adding$Radar/index.html");
                if (poiData != null) {
                    JSONArray pass = new JSONArray();
                    final String ATTR_ID = "id";
                    final String ATTR_NAME = "name";
                    final String ATTR_DESCRIPTION = "description";
                    final String ATTR_LATITUDE = "latitude";
                    final String ATTR_LONGITUDE = "longitude";
                    final String ATTR_ALTITUDE = "altitude";
                    int i = position - 1;
                    //for (int i = 0; i <  poiData.length(); i++) {
                    JSONObject jsonObj = (JSONObject) poiData.get(i);
                    final HashMap<String, String> poiInformation = new HashMap<String, String>();
                    poiInformation.put(ATTR_ID, String.valueOf(i));
                    poiInformation.put(ATTR_NAME,
                            new String(jsonObj.getString("name").getBytes("ISO-8859-1"), "UTF-8"));
                    if (jsonObj.getString("score").equalsIgnoreCase("null")) {
                        poiInformation.put(ATTR_DESCRIPTION,
                                new String(jsonObj.getString("address").getBytes("ISO-8859-1"), "UTF-8"));
                    } else {
                        poiInformation.put(ATTR_DESCRIPTION, "" + jsonObj.getDouble("score") + ", "
                                + new String(jsonObj.getString("address").getBytes("ISO-8859-1"), "UTF-8"));
                    }
                    poiInformation.put(ATTR_LATITUDE, String.valueOf(jsonObj.get("x")));
                    poiInformation.put(ATTR_LONGITUDE, String.valueOf(jsonObj.get("y")));
                    final float UNKNOWN_ALTITUDE = -32768f; // equals "AR.CONST.UNKNOWN_ALTITUDE" in JavaScript (compare AR.GeoLocation specification)
                    // Use "AR.CONST.UNKNOWN_ALTITUDE" to tell ARchitect that altitude of places should be on user level. Be aware to handle altitude properly in locationManager in case you use valid POI altitude value (e.g. pass altitude only if GPS accuracy is <7m).
                    poiInformation.put(ATTR_ALTITUDE, String.valueOf(UNKNOWN_ALTITUDE));
                    pass.put(new JSONObject(poiInformation));
                    //}   
                    intent.putExtra("poiData", pass.toString());
                }

                /* launch activity */
                ctx.startActivity(intent);

            } catch (Exception e) {
                /*
                 * may never occur, as long as all SampleActivities exist and are
                 * listed in manifest
                 */
                Toast.makeText(ctx, className + "\nnot defined/accessible", Toast.LENGTH_SHORT).show();
            }

        }
    });

    setContentView(mCardScroller);
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.ours.asyncisover");
    filter.addCategory("android.intent.category.DEFAULT");
    registerReceiver(myBroadcastReceiver, filter);
    isReceiverRegistered = true;

}

From source file:com.example.mycar.MainActivity.java

private IntentFilter getIntentFilter() {

    IntentFilter filter = new IntentFilter();
    filter.addAction(MainActivity.ACTION_DEVICE_DISCOVERED);
    filter.addAction(MainActivity.ACTION_CONNECTED);
    filter.addAction(MainActivity.ACTION_DISCONNECTED);
    return filter;
}

From source file:com.mobicage.rogerthat.plugins.scan.ProcessScanActivity.java

@Override
protected void onServiceBound() {
    T.UI();/* w  w  w .  ja va2s .c o  m*/

    mFriendsPlugin = mService.getPlugin(FriendsPlugin.class);
    mBroadcastReceiver = getBroadcastReceiver();

    final IntentFilter filter = new IntentFilter(FriendsPlugin.FRIEND_INFO_RECEIVED_INTENT);
    filter.addAction(FriendsPlugin.SERVICE_ACTION_INFO_RECEIVED_INTENT);
    filter.addAction(URL_REDIRECTION_DONE);
    registerReceiver(mBroadcastReceiver, filter);

    Intent intent = getIntent();
    final String url = intent.getStringExtra(URL);
    final String emailHash = intent.getStringExtra(EMAILHASH);

    if (url == null && emailHash == null) {
        L.bug("url == null && emailHash == null");
        finish();
    } else {
        startSpinner(intent.getBooleanExtra(SCAN_RESULT, false));
        if (url != null)
            processUrl(url);
        else
            processEmailHash(emailHash);
    }
}

From source file:com.customprogrammingsolutions.MediaStreamer.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    urlBar = (EditText) findViewById(R.id.url_bar);
    errorText = (TextView) findViewById(R.id.stream_error_text);
    mediaStateButton = (ImageButton) findViewById(R.id.media_state_indicator_button);

    mediaStateButton.setOnClickListener(this);

    pd = new ProgressDialog(this);
    pd.setTitle("Connecting");
    pd.setMessage("Connecting to stream...");
    pd.setIndeterminate(true);/*from   w w w  .  jav  a  2 s  .co m*/
    pd.setCancelable(true);
    pd.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            startService(new Intent(CANCEL_PLAYBACK_INTENT));
        }

    });

    IntentFilter myActions = new IntentFilter();
    myActions.addAction(ERROR_INTENT);
    myActions.addAction(CLEAR_ERROR_INTENT);
    myActions.addAction(STOPPED_PLAYBACK_INTENT);
    myActions.addAction(STARTED_PLAYBACK_INTENT);
    registerReceiver(mReceiver, myActions);

    setUpTabs();

    registerForContextMenu(recents);
    registerForContextMenu(favorites);
}

From source file:com.frostwire.android.gui.fragments.BrowsePeerFragment.java

private void initBroadcastReceiver() {
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.ACTION_REFRESH_FINGER);
    filter.addAction(Constants.ACTION_MEDIA_PLAYER_PLAY);
    filter.addAction(Constants.ACTION_MEDIA_PLAYER_PAUSED);
    filter.addAction(Constants.ACTION_MEDIA_PLAYER_STOPPED);
    filter.addAction(Constants.ACTION_FILE_ADDED_OR_REMOVED);
    filter.addAction(MusicPlaybackService.META_CHANGED);
    filter.addAction(MusicPlaybackService.PLAYSTATE_CHANGED);
    getActivity().registerReceiver(broadcastReceiver, filter);
}

From source file:by.zatta.pilight.connection.ConnectionService.java

@Override
public void onCreate() {
    Log.v(TAG, "onCreate");
    super.onCreate();
    ctx = this;//from w w  w  . j  a  va  2  s .  com
    aCtx = getApplicationContext();

    SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String language = getPrefs.getString("languagePref", "unknown");
    if (!language.equals("unknown"))
        makeLocale(language);

    IntentFilter filter = new IntentFilter();
    filter.addAction("pilight-reconnect");
    filter.addAction("pilight-kill-service");
    filter.addAction("pilight-switch-device");
    this.registerReceiver(mMessageReceiver, filter);

    mNotMan = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    isConnectionUp = makeConnection();
    isDestroying = false;
    Log.v(TAG, "onCreate done");

}

From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java

@Override
public void onResume() {
    super.onResume();
    HANDLER_FLAG = true;/*from w ww  .j  a  v a2  s .  co  m*/
    Utils.setUpActionBar(getActivity(), getResources().getString(R.string.rdk_emulator_view));
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    getActivity().registerReceiver(mGattUpdateReceiver, intentFilter);
    initializeBondingIFnotBonded();
}

From source file:com.keepassdroid.EntryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mShowPassword = !prefs.getBoolean(getString(R.string.maskpass_key),
            getResources().getBoolean(R.bool.maskpass_default));

    super.onCreate(savedInstanceState);
    setEntryView();//from   www  .  jav  a2 s .  c o  m

    Context appCtx = getApplicationContext();
    dateFormat = android.text.format.DateFormat.getDateFormat(appCtx);
    timeFormat = android.text.format.DateFormat.getTimeFormat(appCtx);

    Database db = App.getDB();
    // Likely the app has been killed exit the activity 
    if (!db.Loaded()) {
        finish();
        return;
    }
    readOnly = db.readOnly;

    setResult(KeePass.EXIT_NORMAL);

    Intent i = getIntent();
    UUID uuid = Types.bytestoUUID(i.getByteArrayExtra(KEY_ENTRY));
    mPos = i.getIntExtra(KEY_REFRESH_POS, -1);
    assert (uuid != null);

    mEntry = db.pm.entries.get(uuid);
    if (mEntry == null) {
        Toast.makeText(this, R.string.entry_not_found, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    // Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set
    this.invalidateOptionsMenu();

    // Update last access time.
    mEntry.touch(false, false);

    fillData(false);

    setupEditButtons();

    // Notification Manager
    NotificationUtil.createChannels(getApplicationContext());
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    if (mEntry.getPassword().length() > 0) {
        // only show notification if password is available
        Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
        mNM.notify(NOTIFY_PASSWORD, password);
    }

    if (mEntry.getUsername().length() > 0) {
        // only show notification if username is available
        Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
        mNM.notify(NOTIFY_USERNAME, username);
    }

    mIntentReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (action.equals(Intents.COPY_USERNAME)) {
                String username = mEntry.getUsername();
                if (username.length() > 0) {
                    timeoutCopyToClipboard(username);
                }
            } else if (action.equals(Intents.COPY_PASSWORD)) {
                String password = new String(mEntry.getPassword());
                if (password.length() > 0) {
                    timeoutCopyToClipboard(new String(mEntry.getPassword()));
                }
            }
        }
    };

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intents.COPY_USERNAME);
    filter.addAction(Intents.COPY_PASSWORD);
    registerReceiver(mIntentReceiver, filter);
}