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:com.hypodiabetic.happ.MainActivity.java

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

    //xdrip start
    extendedGraphBuilder = new ExtendedGraphBuilder(getApplicationContext());

    _broadcastReceiver = new BroadcastReceiver() {
        @Override//from  ww w.j av a 2  s.co  m
        public void onReceive(Context ctx, Intent intent) {
            if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) {
                setupBGCharts();
                displayCurrentInfo();
                holdViewport.set(0, 0, 0, 0);
            }
        }
    };
    newDataReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context ctx, Intent intent) {
            setupBGCharts();
            displayCurrentInfo();
            holdViewport.set(0, 0, 0, 0);
        }
    };
    registerReceiver(_broadcastReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
    registerReceiver(newDataReceiver, new IntentFilter(Intents.ACTION_NEW_BG));
    setupBGCharts();
    displayCurrentInfo();
    holdViewport.set(0, 0, 0, 0);
    //xdrip end

    //listens out for new Stats
    newStatsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            Stats stat = gson.fromJson(intent.getStringExtra("stat"), Stats.class);

            updateStats(stat);
            displayCurrentInfo();
        }
    };
    registerReceiver(newStatsReceiver, new IntentFilter("ACTION_UPDATE_STATS"));
    updateStats(null);

    //listens out for openAPS updates
    newAPSUpdate = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
            APSResult apsResult = gson.fromJson(intent.getStringExtra("APSResult"), APSResult.class);

            updateOpenAPSDetails(apsResult);
            setupBGCharts();
            displayCurrentInfo();
        }
    };
    registerReceiver(newAPSUpdate, new IntentFilter("APS_UPDATE"));

    //listens out for app notifications
    appNotification = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int snackbar_length;
            snackbar_length = intent.getIntExtra("snackbar_length", Snackbar.LENGTH_INDEFINITE);
            final String alertDialogText = intent.getStringExtra("alertDialogText");
            String snackBarMsg = intent.getStringExtra("snackBarMsg");

            Snackbar snackbar = Snackbar
                    .make(MainActivity.activity.findViewById(R.id.mainActivity), snackBarMsg, snackbar_length)
                    .setAction("DETAILS", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity);
                            builder.setMessage(alertDialogText);
                            builder.setPositiveButton("OK", null);
                            builder.show();
                        }
                    });
            snackbar.show();

        }
    };
    registerReceiver(appNotification, new IntentFilter("NEW_APP_NOTIFICATION"));

}

From source file:edu.mit.mobile.android.locast.sync.AbsMediaSync.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (ACTION_SYNC_RESOURCES.equals(intent.getAction())) {
        final Uri data = intent.getData();
        if (data == null) {
            try {
                enqueueUnpublishedMedia();
            } catch (final SyncException e) {
                Log.e(TAG, "cannot sync request URL", e);
            }/*from  w w  w.  j  a v  a 2 s .c  om*/

        } else {
            enqueueItem(data, intent.getExtras());
        }
    } else {
        Log.e(TAG, "Media Sync was told to start with an unhandled intent: " + intent);
    }

    return START_REDELIVER_INTENT;
}

From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.activity_feed_edit);
    setResult(RESULT_CANCELED);/*from  w w  w.j av  a2  s. c  o m*/

    Intent intent = getIntent();

    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View filtersLayout = findViewById(R.id.filters_layout);
    View buttonLayout = findViewById(R.id.button_layout);

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        filtersLayout.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }

        restoreInstanceState(savedInstanceState);
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        buttonLayout.setVisibility(View.GONE);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, null);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (!restoreInstanceState(savedInstanceState)) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor.moveToNext()) {
                mPreviousName = cursor.getString(0);
                mNameEditText.setText(mPreviousName);
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                cursor.close();
            } else {
                cursor.close();
                Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }
}

From source file:co.nerdart.ourss.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.feed_edit);/*from  w  w  w  . ja  v  a 2  s .c  om*/
    setResult(RESULT_CANCELED);

    Intent intent = getIntent();

    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View filtersLayout = findViewById(R.id.filters_layout);
    View buttonLayout = findViewById(R.id.button_layout);

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        filtersLayout.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }

        restoreInstanceState(savedInstanceState);
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        buttonLayout.setVisibility(View.GONE);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, null);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (!restoreInstanceState(savedInstanceState)) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor.moveToNext()) {
                mPreviousName = cursor.getString(0);
                mNameEditText.setText(mPreviousName);
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                cursor.close();
            } else {
                cursor.close();
                Crouton.makeText(EditFeedActivity.this, R.string.error, Style.INFO);
                finish();
            }
        }
    }
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    if (intent != null) {
        String action = intent.getAction();
        if ((action != null) && action.equals(Intent.ACTION_SEND)) {
            if (intent.hasExtra(Intent.EXTRA_STREAM))
                getPhoto((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
            if (intent.hasExtra(Intent.EXTRA_TEXT)) {
                final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                mMessage.setText(text);/*from w w  w .ja  v  a2 s . c  o m*/
                mCount.setText(Integer.toString(text.length()));
            }
            chooseAccounts();
        } else {
            Uri data = intent.getData();
            if ((data != null) && data.toString().contains(Accounts.getContentUri(this).toString())) {
                // default to the account passed in, but allow selecting additional accounts
                Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID, Accounts.SERVICE }, Accounts._ID + "=?",
                        new String[] { data.getLastPathSegment() }, null);
                if (account.moveToFirst())
                    mAccountsService.put(account.getLong(0), account.getInt(1));
                account.close();
            } else if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
                // check if a photo path was passed and prompt user to select the account
                setPhoto(intent.getStringExtra(Widgets.INSTANT_UPLOAD));
                chooseAccounts();
            }
        }
    }
}

From source file:edu.cmu.mpcs.dashboard.TagViewer.java

void resolveIntent(Intent intent) {
    // Parse the intent
    String action = intent.getAction();
    Log.d("TAG_VIEWER", "in resolve intent");
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        // When a tag is discovered we send it to the service to
        // be save. We
        // include a PendingIntent for the service to call back
        // onto. This
        // will cause this activity to be restarted with
        // onNewIntent(). At
        // that time we read it from the database and view it.
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        NdefMessage[] msgs;//from   ww w  .  ja v a 2 s  . c  om
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
        } else {
            // Unknown tag type
            byte[] empty = new byte[] {};
            NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
            NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
            msgs = new NdefMessage[] { msg };
        }
        // Setup the views
        setTitle(R.string.title_scanned_tag);
        buildTagViews(msgs);
    } else {
        Log.e(TAG, "Unknown intent " + intent);
        // finish();
        return;
    }
}

From source file:android.support.v7.media.RemotePlaybackClient.java

void handleInvalidResult(Intent intent, ActionCallback callback, Bundle data) {
    Log.w(TAG, "Received invalid result data from " + intent.getAction() + ": data=" + bundleToString(data));
    callback.onError(null, MediaControlIntent.ERROR_UNKNOWN, data);
}

From source file:it.feio.android.omninotes.async.DataBackupIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    prefs = getSharedPreferences(Constants.PREFS_NAME, MODE_MULTI_PROCESS);

    // Creates an indeterminate processing notification until the work is complete
    mNotificationsHelper = new NotificationsHelper(this)
            .createNotification(R.drawable.ic_content_save_white_24dp, getString(R.string.working), null)
            .setIndeterminate().setOngoing().show();

    // If an alarm has been fired a notification must be generated
    if (ACTION_DATA_EXPORT.equals(intent.getAction())) {
        exportData(intent);/*w ww  . j  av a2s  .c om*/
    } else if (ACTION_DATA_IMPORT.equals(intent.getAction())) {
        importData(intent);
    } else if (ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) {
        importDataFromSpringpad(intent);
    } else if (ACTION_DATA_DELETE.equals(intent.getAction())) {
        deleteData(intent);
    }
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
void onDictionaryServiceReady() {
    if (this.backItems.isEmpty()) {
        final Intent intent = getIntent();
        if (intent != null && intent.getAction() != null) {
            String action = intent.getAction();
            String _word = null;//from  ww w .j a  va2 s .  com
            if (action.equals(Intent.ACTION_SEARCH)) {
                _word = intent.getStringExtra("query");
            } else if (action.equals(Intent.ACTION_SEND)) {
                _word = intent.getStringExtra(Intent.EXTRA_TEXT);
            }

            final String word = _word;

            if (word != null) {

                if (currentTask != null) {
                    currentTask.cancel();
                }

                currentTask = new TimerTask() {
                    @Override
                    public void run() {
                        setProgress(500);
                        String currentWord = word;
                        Log.d(TAG, "intent.getDataString(): " + intent.getDataString());
                        while (currentWord.length() > 0) {
                            Iterator<Entry> results = dictionaryService.lookup(currentWord);
                            Log.d(TAG, "Looked up " + word);
                            if (results.hasNext()) {
                                currentTask = null;
                                Entry entry = results.next();
                                showArticle(entry);
                                break;
                            } else {
                                currentWord = currentWord.substring(0, currentWord.length() - 1);
                            }
                        }
                        if (currentWord.length() == 0) {
                            onSearchRequested();
                        }
                    }
                };

                try {
                    timer.schedule(currentTask, 0);
                } catch (Exception e) {
                    Log.d(TAG, "Failed to schedule task", e);
                    showError(getString(R.string.msgErrorLoadingArticle, word));
                }
            }
        } else {
            String word = intent.getStringExtra("word");
            String section = intent.getStringExtra("section");
            String volumeId = intent.getStringExtra("volumeId");
            long articlePointer = intent.getLongExtra("articlePointer", -1);
            dictionaryService.setPreferred(volumeId);
            showArticle(volumeId, articlePointer, word, section);
        }
    } else {
        showCurrentArticle();
    }
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private void handleIntent(@Nonnull final Intent intent) {
    final String action = intent.getAction();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        final String inputType = intent.getType();
        final NdefMessage ndefMessage = (NdefMessage) intent
                .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
        final byte[] input = Nfc.extractMimePayload(Constants.MIMETYPE_TRANSACTION, ndefMessage);

        new BinaryInputParser(inputType, input) {
            @Override/*from w  w w.  j  a va2s . co m*/
            protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
                cannotClassify(inputType);
            }

            @Override
            protected void error(final int messageResId, final Object... messageArgs) {
                dialog(WalletActivity.this, null, 0, messageResId, messageArgs);
            }
        }.parse();
    }
}