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:edu.stanford.junction.sample.partyware.ImgurUploadService.java

/**
 * //from  w  w w. jav  a 2s .  co  m
 * @return a map that contains objects with the following keys:
 * 
 *         delete - the url used to delete the uploaded image (null if
 *         error).
 * 
 *         original - the url to the uploaded image (null if error) The map
 *         is null if error
 */
private Map<String, String> handleSendIntent(final Intent intent) {
    Log.i(this.getClass().getName(), "in handleResponse()");

    Log.d(this.getClass().getName(), intent.toString());
    final Bundle extras = intent.getExtras();
    try {
        //upload a new image
        if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)
                && extras.containsKey(Intent.EXTRA_STREAM)) {

            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (uri != null) {
                Log.d(this.getClass().getName(), uri.toString());
                imageLocation = uri;
                final String jsonOutput = readPictureDataAndUpload(uri);
                return parseJSONResponse(jsonOutput);
            }
            Log.e(this.getClass().getName(), "URI null");
        }
    } catch (final Exception e) {
        Log.e(this.getClass().getName(), "Completely unexpected error", e);
    }
    return null;
}

From source file:com.ekumen.tangobot.application.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    // Load raw resources
    for (Pair<Integer, String> ip : mResourcesToLoad) {
        mOpenedResources.add(new ParameterLoaderNode.Resource(
                getResources().openRawResource(ip.first.intValue()), ip.second));
    }// ww w . jav  a2s.c  o  m

    mSharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // UI
    initializeUI();

    // USB handling code
    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    mUsbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    mUsbAttachedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mLog.info("Received USB Intent");
            if (intent.getAction() == ACTION_USB_PERMISSION
                    && intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                onDeviceReady((UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE));
            }
        }
    };
    mUsbDetachedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mLog.info("Received USB disconnection Intent");
            UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            onDeviceDetached(device);
        }
    };
}

From source file:li.barter.chat.ChatService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {

    final String action = intent != null ? intent.getAction() : null;

    if ((action != null) && action.equals(AppConstants.ACTION_DISCONNECT_CHAT)) {

        if (isConnectedToChat()) {

            mMessageConsumer.dispose(true);
            mMessageConsumer = null;//  w  w w. j  a  v a  2s.  c o  m
        }
    } else {
        mCurrentConnectMultiplier = 0;
        initMessageConsumer();
        connectChatService();
    }

    return START_STICKY;
}

From source file:io.scalac.locationprovider.SendMockLocationService.java

@Override
public int onStartCommand(Intent startIntent, int flags, int startId) {
    // Get the type of test to run
    mTestRequest = startIntent.getAction();

    /*/* w  ww .  j  av a 2s . c o  m*/
     * If the incoming Intent was a request to run a one-time or continuous test
     */
    if ((TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_ONCE))
            || (TextUtils.equals(mTestRequest, LocationUtils.ACTION_START_CONTINUOUS))) {

        // Get the pause interval and injection interval
        mPauseInterval = startIntent.getIntExtra(LocationUtils.EXTRA_PAUSE_VALUE, 2);
        mInjectionInterval = startIntent.getIntExtra(LocationUtils.EXTRA_SEND_INTERVAL, 1);
        mMockId = startIntent.getStringExtra(LocationUtils.EXTRA_MOCK_ID);

        // Post a notification in the notification bar that a test is starting
        postNotification(getString(R.string.notification_content_test_start));

        // Create a location client
        mLocationClient = new LocationClient(this, this, this);

        // Start connecting to Location Services
        mLocationClient.connect();

    } else if (TextUtils.equals(mTestRequest, LocationUtils.ACTION_STOP_TEST)) {

        // Remove any existing notifications
        removeNotification();

        // Send a message back to the main activity that the test is stopping
        sendBroadcastMessage(LocationUtils.CODE_TEST_STOPPED, 0);

        // Stop this Service
        stopSelf();
    }

    /*
     * Tell the system to keep the Service alive, but to discard the Intent that
     * started the Service
     */
    return Service.START_STICKY;
}

From source file:com.googlecode.android_scripting.facade.ui.NFCBeamTask.java

@SuppressLint("NewApi")
@Override//w  ww  .  j  ava 2 s.co  m
public void onNewIntent(Intent intent) {
    Log.d(TAG, "onNewIntent");

    if (intent.getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
        NdefMessage[] msgs = getNdefMessagesFromIntent(intent);
        NdefRecord record = msgs[0].getRecords()[0];
        byte[] payload = record.getPayload();

        String payloadString = new String(payload);

        //Toast.makeText(getActivity().getApplicationContext(), payloadString, Toast.LENGTH_SHORT).show();

        this.content = payloadString;
        setResult("slave", "ok");

    } else if (intent.getAction().equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
        Toast.makeText(getActivity().getApplicationContext(), "This NFC tag has no NDEF data.",
                Toast.LENGTH_LONG).show();
    }
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    Theme.checkTheme(this);

    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
    StrictModeUtil.enable();// w w w.  jav  a  2s.  c o  m

    // Set up the action bar.
    setSupportActionBar(mBinding.toolbarTabs.toolbar);
    ActionBar supportActionBar = getSupportActionBar();
    assert supportActionBar != null;
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    supportActionBar.setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mBinding.drawerLayout, /* DrawerLayout object */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */);

    // Explanation of setDrawerIndicatorEnabled and setHomeAsUpIndicator:
    // We want to only have a hamburger icon, always, without any animation.

    // If we don't call either of these methods, we use the default indicator,
    // which is the hamburger icon transitioning to a left-arrow icon, as the drawer is opened.

    // If we only call setDrawerIndicatorUpEnabled, we'll have the left arrow icon always.

    // If we only call setHomeAsUpIndicator (with a hamburger icon), we'll have a hamburger icon
    // but with a bug: If you open the drawer, rotate, and close it, you'll have the left arrow
    // again.

    // With the combination of both setDrawerIndicatorEnabled and setHomeAsUpIndicator, we
    // have a hamburger icon always.
    mDrawerToggle.setDrawerIndicatorEnabled(false);
    mDrawerToggle.setHomeAsUpIndicator(new DrawerArrowDrawable(this));

    mMainPagerAdapter = new MainPagerAdapter(this, getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mBinding.pager.setAdapter(mMainPagerAdapter);
    mBinding.toolbarTabs.tabs.setupWithViewPager(mBinding.pager);

    // If our activity was opened by choosing a file from a mail attachment, file browser, or other program,
    // import the database from this file.
    Intent intent = getIntent();
    if (intent != null) {
        if (Intent.ACTION_VIEW.equals(intent.getAction()))
            importDB(intent.getData());
    }

    // Register various observers.
    mTeamsObserver = new TeamsObserver(this, mOnTeamsChangedListener);
    mOnTeamsChangedListener.onTeamsChanged();
    mTeamsObserver.register();
    mTeamNavigationMenu = new TeamNavigationMenu(this, mBinding.leftDrawer.getMenu());
    mTeamNavigationMenu.load();
    mBinding.leftDrawer.setNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    IntentFilter filter = new IntentFilter(ACTION_IMPORT_COMPLETE);
    filter.addAction(ACTION_EXPORT_COMPLETE);
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mBroadcastReceiver, filter);
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

/**
 * /* w w  w  .  ja v a  2s.  co  m*/
 * @return a map that contains objects with the following keys:
 * 
 *         delete - the url used to delete the uploaded image (null if
 *         error).
 * 
 *         original - the url to the uploaded image (null if error) The map
 *         is null if error
 */
private Map<String, String> handleSendIntent(final Intent intent) {
    Log.i(this.getClass().getName(), "in handleResponse()");

    Log.d(this.getClass().getName(), intent.toString());
    final Bundle extras = intent.getExtras();
    try {
        //upload a new image
        if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)
                && extras.containsKey(Intent.EXTRA_STREAM)) {

            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (uri != null) {
                Log.d(this.getClass().getName(), uri.toString());
                // store uri so we can create the thumbnail if we succeed
                imageLocation = uri;
                final String jsonOutput = readPictureDataAndUpload(uri);
                return parseJSONResponse(jsonOutput);
            }
            Log.e(this.getClass().getName(), "URI null");
        }
    } catch (final Exception e) {
        Log.e(this.getClass().getName(), "Completely unexpected error", e);
    }
    return null;
}

From source file:at.alladin.rmbt.android.test.RMBTService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    String action = null;/*from   ww  w  . j  ava  2 s. c om*/
    if (intent != null)
        action = intent.getAction();

    Log.i(DEBUG_TAG, "onStartCommand; action=" + action);

    if (ACTION_ABORT_TEST.equals(action)) {
        Log.i(DEBUG_TAG, "ACTION_ABORT_TEST received");
        stopTest(BROADCAST_TEST_ABORTED);
        return START_NOT_STICKY;
    }

    if (ACTION_START_TEST.equals(action) || ACTION_LOOP_TEST.equals(action)) {
        if (testTask != null && testTask.isRunning()) {
            if (ACTION_LOOP_TEST.equals(action)) // do not cancel test if running in loop mode 
                return START_STICKY;
            testTask.cancel(); // otherwise cancel
        }

        completed = false;

        running.set(true);

        // lock wifi + power
        lock();
        testTask = new RMBTTask(getApplicationContext());

        testTask.setEndTaskListener(this);
        testTask.execute(handler);

        Log.d(DEBUG_TAG, "RMBTTest started");

        handler.postDelayed(addNotificationRunnable, 200);
        handler.postDelayed(deadman, DEADMAN_TIME);

        return START_STICKY;
    }
    return START_NOT_STICKY;
}

From source file:com.jesusla.google.BillingService.java

/**
 * The {@link BillingReceiver} sends messages to this service using intents.
 * Each intent has an action and some extra arguments specific to that action.
 * @param intent the intent containing one of the supported actions
 * @param startId an identifier for the invocation instance of this service
 *//*  w w  w .  ja  v  a 2s  . c o m*/
public void handleCommand(Intent intent, int startId) {
    String action = intent.getAction();
    if (Consts.DEBUG) {
        Log.i(TAG, "handleCommand() action: " + action);
    }
    if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
        String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID);
        confirmNotifications(startId, notifyIds);
    } else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) {
        String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID);
        getPurchaseInformation(startId, new String[] { notifyId });
    } else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
        String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA);
        String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE);
        purchaseStateChanged(startId, signedData, signature);
    } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) {
        long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1);
        int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE,
                ResponseCode.RESULT_ERROR.ordinal());
        ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex);
        checkResponseCode(requestId, responseCode);
    }
}