Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

In this page you can find the example usage for android.content Intent getAction.

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:alaindc.crowdroid.SendIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        // DIFFERENTIATE like in sensorIntentService per each sensor!
        if (action.startsWith(Constants.ACTION_SENDDATA)) {
            handleActionSendData(intent.getIntExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND, -1)); // Name in shared preference
        } else if (action.startsWith(Constants.ACTION_RECEIVEDDATA)) {
            final String response = intent.getStringExtra(Constants.EXTRA_SENSE_RESPONSE);
            handleActionReceivedData(response);
        } else if (action.startsWith(Constants.ACTION_GETSUBSCRIPTION)) {
            handleActionGetSubscriptions();
        } else if (action.startsWith(Constants.ACTION_UPDATESUBSCRIPTION)) {
            handleActionUpdateSubscriptions(intent.getStringExtra(Constants.EXTRA_BODY_UPDATESUBSCRIPTION));
        } else if (action.startsWith(Constants.ACTION_RECEIVEDSUBSCRIPTION)) {
            handleActionReceivedSubscriptions(intent.getStringExtra(Constants.EXTRA_SUBSCRIPTION_RESPONSE));
        } else if (action.startsWith(Constants.ACTION_RECEIVEDTHROUGHPUT)) {
            handleActionReceivedThroughput(intent.getLongExtra(Constants.EXTRA_THROUGHPUT_RESPONSE, -1));
        }/*from   www  .ja va2 s. c  o  m*/
    }
}

From source file:android.support.mediacompat.service.ServiceBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();/*from  www. java  2  s  .  c  om*/
    if (ACTION_CALL_MEDIA_BROWSER_SERVICE_METHOD.equals(intent.getAction()) && extras != null) {
        StubMediaBrowserServiceCompat service = StubMediaBrowserServiceCompat.sInstance;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case NOTIFY_CHILDREN_CHANGED:
            service.notifyChildrenChanged(extras.getString(KEY_ARGUMENT));
            break;
        case SEND_DELAYED_NOTIFY_CHILDREN_CHANGED:
            service.sendDelayedNotifyChildrenChanged();
            break;
        case SEND_DELAYED_ITEM_LOADED:
            service.sendDelayedItemLoaded();
            break;
        case CUSTOM_ACTION_SEND_PROGRESS_UPDATE:
            service.mCustomActionResult.sendProgressUpdate(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_ERROR:
            service.mCustomActionResult.sendError(extras.getBundle(KEY_ARGUMENT));
            break;
        case CUSTOM_ACTION_SEND_RESULT:
            service.mCustomActionResult.sendResult(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_SESSION_TOKEN:
            StubMediaBrowserServiceCompatWithDelayedMediaSession.sInstance.callSetSessionToken();
            break;
        }
    } else if (ACTION_CALL_MEDIA_SESSION_METHOD.equals(intent.getAction()) && extras != null) {
        MediaSessionCompat session = StubMediaBrowserServiceCompat.sSession;
        int method = extras.getInt(KEY_METHOD_ID, 0);

        switch (method) {
        case SET_EXTRAS:
            session.setExtras(extras.getBundle(KEY_ARGUMENT));
            break;
        case SET_FLAGS:
            session.setFlags(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_METADATA:
            session.setMetadata((MediaMetadataCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_STATE:
            session.setPlaybackState((PlaybackStateCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_QUEUE:
            List<QueueItem> items = extras.getParcelableArrayList(KEY_ARGUMENT);
            session.setQueue(items);
            break;
        case SET_QUEUE_TITLE:
            session.setQueueTitle(extras.getCharSequence(KEY_ARGUMENT));
            break;
        case SET_SESSION_ACTIVITY:
            session.setSessionActivity((PendingIntent) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_CAPTIONING_ENABLED:
            session.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT));
            break;
        case SET_REPEAT_MODE:
            session.setRepeatMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_SHUFFLE_MODE:
            session.setShuffleMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SEND_SESSION_EVENT:
            Bundle arguments = extras.getBundle(KEY_ARGUMENT);
            session.sendSessionEvent(arguments.getString("event"), arguments.getBundle("extras"));
            break;
        case SET_ACTIVE:
            session.setActive(extras.getBoolean(KEY_ARGUMENT));
            break;
        case RELEASE:
            session.release();
            break;
        case SET_PLAYBACK_TO_LOCAL:
            session.setPlaybackToLocal(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_PLAYBACK_TO_REMOTE:
            ParcelableVolumeInfo volumeInfo = extras.getParcelable(KEY_ARGUMENT);
            session.setPlaybackToRemote(new VolumeProviderCompat(volumeInfo.controlType, volumeInfo.maxVolume,
                    volumeInfo.currentVolume) {
            });
            break;
        case SET_RATING_TYPE:
            session.setRatingType(RatingCompat.RATING_5_STARS);
            break;
        }
    }
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

protected void submitImage(String tags) {
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();/* ww w  . j  a  va 2 s  .c  o m*/
    Uri mImageUri = null;
    File mFilename = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                Cursor cursor = getContentResolver().query(mImageUri, null, null, null, null);
                if (cursor.moveToFirst()) {
                    mFilename = new File(cursor.getString(cursor.getColumnIndexOrThrow(ImageColumns.DATA)));
                }
                cursor.close();
                if (mFilename != null) {
                    ZeitGeistReichUploaderTask task = new ZeitGeistReichUploaderTask();
                    ZeitGeistObject o = new ZeitGeistObject(mFilename, tags);
                    task.execute(o);
                }
            }
        }
    }
}

From source file:com.oliversride.wordryo.UpdateCheckReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (null != intent && null != intent.getAction()
            && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        restartTimer(context);//  w ww .  ja  v  a2  s .c  o  m
    } else {
        checkVersions(context, false);
        restartTimer(context);
    }
}

From source file:de.quist.app.errorreporter.ExceptionReportService.java

@Override
protected void onHandleIntent(Intent intent) {
    try {//from w  w w . jav  a 2  s . co m
        if (intent.getAction().equals(ACTION_SEND_REPORT)) {
            sendReport(intent);
        }
    } catch (Exception e) {
        // Catch all other exceptions as otherwise they would create an endless loop
        Log.e(TAG, "Error while sending an error report", e);
    }
}

From source file:it.gulch.linuxday.android.services.AlarmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    switch (action) {
    case ACTION_UPDATE_ALARMS:
        updateAlarms(intent);/*from  w ww .  j  av a  2  s. c  o  m*/
        break;
    case ACTION_DISABLE_ALARMS:
        disableAlarms();
        break;
    case ActionConstants.ACTION_ADD_BOOKMARK:
        addBookmark(intent);
        break;
    case ActionConstants.ACTION_REMOVE_BOOKMARKS:
        removeBookmarks(intent);
        break;
    case AlarmReceiver.ACTION_NOTIFY_EVENT:
        notifyEvent(intent);
        AlarmReceiver.completeWakefulIntent(intent);
        break;
    }

    // TODO: ELSE?
}

From source file:com.opemind.cartspage.client.android.book.SearchBookContentsActivity.java

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

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();
    if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) {
        finish();/*from w w w .ja va 2  s  .  c om*/
        return;
    }

    isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    if (LocaleManager.isBookSearchUrl(isbn)) {
        setTitle(getString(R.string.sbc_name));
    } else {
        setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
    }

    setContentView(R.layout.search_book_contents);
    queryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && !initialQuery.isEmpty()) {
        // Populate the search box but don't trigger the search
        queryTextView.setText(initialQuery);
    }
    queryTextView.setOnKeyListener(keyListener);

    queryButton = findViewById(R.id.query_button);
    queryButton.setOnClickListener(buttonListener);

    resultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    headerView = (TextView) factory.inflate(R.layout.search_book_contents_header, resultListView, false);
    resultListView.addHeaderView(headerView);
}

From source file:alaindc.crowdroid.SensorsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (action.equals(Constants.INTENT_START_SENSORS)) {

            // Init throughput taken
            SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
            editor.commit();/*  ww  w . j  a  v  a  2s  . c  o m*/

            // Configure sensors and eventlistener
            mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensorList) {
                if (Constants.isInMonitoredSensors(sensor.getType()))
                    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
            }

            // TODO STUB: Comment this in release
            for (int type : Constants.STUBBED_MONITORED_SENSORS) {
                stub_onSensorChanged(type);
            }

        }

        if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) {
            // Configure amplitude and start TEST
            amplitudeTask = new GetAmplitudeTask(this);
            amplitudeTask.getData();
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) {
            double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1);

            if (amplitude > 0) {
                SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude));
                editor.commit();

                // Update view
                Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
                senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
                        "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: "
                                + Double.toString(amplitude));
                LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);
            }

            int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE);

            // Set the alarms for next sensing of amplitude
            alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
            Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
            intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

            // TIMEOUT for another monitoring of audio
            int seconds = 30; // TODO: De-hardcode this
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
                    alarmIntent);

        }
    }
}

From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java

@Override
protected void onHandleIntent(Intent intent) {
    final String action = intent.getAction();

    if (ACTION_NOTIFY_DEBUG.equals(action)) {
        notifyDebug();/*from   ww w  .j a v a2 s  .c om*/
        return;
    }

    if (ACTION_SCHEDULE_ALL_STARRED_MATCHES.equals(action)) {
        scheduleAllStarredMatches();
        return;
    }

    final long matchId = intent.getLongExtra(ReminderAlarmService.EXTRA_MATCH_ID, UNDEFINED_VALUE);

    if (matchId == UNDEFINED_VALUE) {
        return;
    }

    if (ACTION_NOTIFY_MATCH.equals(action)) {
        notifyMatch(matchId);
    }

    final long matchStartTime = intent.getLongExtra(ReminderAlarmService.EXTRA_MATCH_START, UNDEFINED_VALUE);

    if (matchStartTime == UNDEFINED_VALUE) {
        return;
    }

    if (ACTION_SCHEDULE_STARRED_MATCH.equals(action)) {
        scheduleAlarm(matchId, matchStartTime);
    }

    if (ACTION_UNSCHEDULE_STARRED_MATCH.equals(action)) {
        cancelAlarm(matchId, matchStartTime);
    }
}

From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java

private void send() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    Intent originalIntent = getIntent();
    if (Intent.ACTION_SEND.equals(originalIntent.getAction())) {
        // Copy extras from the original intent because they might contain
        // additional information about the URL (e.g., the title of a
        // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid
        // overwriting the TinyURL.
        intent.putExtras(originalIntent.getExtras());
    }/*from ww  w.  j a  va  2s  . c  om*/

    intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl);
    try {
        CharSequence template = getText(R.string.title_send);
        String title = String.format(String.valueOf(template), mTinyUrl);
        startActivity(Intent.createChooser(intent, title));
        finish();
    } catch (ActivityNotFoundException e) {
        handleError(e);
    }
}