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.nextgis.maplibui.service.LayerFillService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LayerFillService", "Received start id " + startId + ": " + intent);
    if (intent != null) {
        String action = intent.getAction();

        if (!TextUtils.isEmpty(action)) {
            switch (action) {
            case ACTION_ADD_TASK:
                int layerGroupId = intent.getIntExtra(KEY_LAYER_GROUP_ID, Constants.NOT_FOUND);
                mLayerGroup = (LayerGroup) MapBase.getInstance().getLayerById(layerGroupId);

                Bundle extra = intent.getExtras();
                int layerType = extra.getInt(KEY_INPUT_TYPE, Constants.NOT_FOUND);

                switch (layerType) {
                case VECTOR_LAYER:
                    mQueue.add(new VectorLayerFillTask(extra));
                    break;
                case VECTOR_LAYER_WITH_FORM:
                    mQueue.add(new UnzipForm(extra));
                    break;
                case TMS_LAYER:
                    mQueue.add(new LocalTMSFillTask(extra));
                    break;
                case NGW_LAYER:
                    mQueue.add(new NGWVectorLayerFillTask(extra));
                    break;
                }/*from  ww w . j a v  a 2  s  . c  om*/

                if (!mIsRunning) {
                    startNextTask();
                }

                return START_STICKY;
            case ACTION_STOP:
                mQueue.clear();
                mIsCanceled = true;
                break;
            case ACTION_SHOW:
                mProgressIntent.putExtra(KEY_STATUS, STATUS_SHOW).putExtra(KEY_TITLE, mBuilder.mContentTitle);
                sendBroadcast(mProgressIntent);
                break;
            }
        }
    }
    return START_STICKY;
}

From source file:jp.co.conit.sss.sp.ex1.billing.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.//from   w w w.j  a  va 2s. c  om
 * 
 * @param intent the intent containing one of the supported actions
 * @param startId an identifier for the invocation instance of this service
 */
public void handleCommand(Intent intent, int startId) {

    if (intent == null) {
        return;
    }

    String action = intent.getAction();

    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);
    }
}

From source file:com.trimble.mcs.cordova.plugin.TrmbMcsRfid.java

public void handleRfidTagIntent(Context context, Intent intent) {
    CallbackContext cb = mScanTagCallback;
    if (cb == null)
        return;/* w  ww . j  ava  2 s .  c om*/

    String action = intent.getAction();

    if (action.equals(RfidConstants.ACTION_RFID_TAG_SCANNED)) {
        // Extract tag data from intent
        String tagID = intent.getStringExtra(RfidConstants.RFID_FIELD_ID);
        String memory = intent.getStringExtra(RfidConstants.RFID_FIELD_MEMORY);
        String tagType = intent.getStringExtra(RfidConstants.RFID_FIELD_TAG_TYPE);
        int rssi = intent.getIntExtra(RfidConstants.RFID_FIELD_RSSI, 0);
        int readCount = intent.getIntExtra(RfidConstants.RFID_FIELD_READ_COUNT, 0);
        long timeStamp = intent.getLongExtra(RfidConstants.RFID_FIELD_TIME_STAMP, 0);

        // Store tag data in a JSON object for transmission to javascript
        JSONObject tagInfo = new JSONObject();
        try {
            if (tagID != null)
                tagInfo.put("tagID", tagID);
            if (memory != null)
                tagInfo.put("memory", memory);
            if (tagType != null)
                tagInfo.put("tagType", tagType);
            if (rssi != 0)
                tagInfo.put("rssi", rssi);
            if (readCount != 0)
                tagInfo.put("readCount", readCount);
            if (timeStamp != 0)
                tagInfo.put("timeStamp", timeStamp);
        } catch (JSONException e) {
            Log.d(TAG, "Error populating JSON object with scan data: " + e.getMessage());
        }

        PluginResult result = new PluginResult(PluginResult.Status.OK, tagInfo);
        result.setKeepCallback(true);
        cb.sendPluginResult(result);
    }
}

From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java

private void handleIntent(Intent intent) {
    String id = null;/*from  w  ww  . j a va2s. c o  m*/
    if (intent != null) {
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            // only one message sent during the beam
            NdefMessage msg = (NdefMessage) rawMsgs[0];
            // record 0 contains the MIME type, record 1 is the AAR, if present
            id = new String(msg.getRecords()[0].getPayload());
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID));
        }
        if (StringUtils.contains(id, "europeana.eu/")) {
            Uri uri = Uri.parse(id);
            List<String> paths = uri.getPathSegments();
            if ((paths != null) && (paths.size() == 4)) {
                String collectionId = paths.get(paths.size() - 2);
                String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html");
                id = StringUtils.join("/", collectionId, "/", recordId);
            } else {
                // invalid url/id, cancel opening record
                id = null;
            }
        }
        if (StringUtils.isNotBlank(id)) {
            openRecord(id);
        }
    }
}

From source file:fr.openbike.android.service.SyncService.java

@SuppressWarnings("unchecked")
@Override//from   www . j a v  a2  s  . c  o m
protected void onHandleIntent(Intent intent) {
    NetworkInfo activeNetwork = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    Bundle bundle = new Bundle();
    int status = STATUS_ERROR;
    if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
        bundle = new Bundle();
        bundle.putString(Intent.EXTRA_TEXT, "No network connectivity");
        receiver.send(STATUS_ERROR, bundle);
        return;
    }
    String action = intent.getAction();
    try {
        if (ACTION_SYNC.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor.executeGet(
                    mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "") + "/v2/stations",
                    new RemoteStationsSyncHandler(
                            prefs.getLong(AbstractPreferencesActivity.STATIONS_VERSION, 0)),
                    this);
            if (result == null) {
                // Need stations update
                action = ACTION_UPDATE;
            } else {
                String message = (String) result;
                status = STATUS_SYNC_STATIONS_FINISHED;
                if (!"".equals(message)) {
                    bundle.putString(EXTRA_RESULT, message);
                }
                prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis())
                        .commit();
            }
        }
        if (ACTION_UPDATE.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_UPDATE_STATIONS, Bundle.EMPTY);
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
            Object result = mRemoteExecutor
                    .executeGet(mPreferences.getString(AbstractPreferencesActivity.UPDATE_SERVER_URL, "")
                            + "/v2/stations/list", new RemoteStationsUpdateHandler(), this);
            status = STATUS_UPDATE_STATIONS_FINISHED;
            if (result != null) {
                bundle.putString(EXTRA_RESULT, (String) result);
            }
            prefs.edit().putLong(AbstractPreferencesActivity.LAST_UPDATE, System.currentTimeMillis()).commit();
        }
        if (ACTION_CHOOSE_NETWORK.equals(action)) {
            if (receiver != null) {
                receiver.send(STATUS_SYNC_NETWORKS, Bundle.EMPTY);
                bundle = new Bundle();
                bundle.putParcelableArrayList(EXTRA_RESULT, (ArrayList<Network>) mRemoteExecutor
                        .executeGet(NETWORKS_URL, new RemoteNetworksHandler(), this));
                status = STATUS_SYNC_NETWORKS_FINISHED;
            }
        }
        if (receiver != null) {
            receiver.send(status, bundle);
        }
    } catch (HandlerException e) {
        if (receiver != null) {
            // Pass back error to surface listener
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    } catch (Exception e) {
        if (receiver != null) {
            // Pass back error to surface listener
            e.printStackTrace();
            bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, "Une erreur est survenue. Veuillez ressayer.");
            receiver.send(STATUS_ERROR, bundle);
        }
    }
}

From source file:com.trimble.mcs.cordova.plugin.TrmbMcsRfid.java

public void handleRfidStatusIntent(Context context, Intent intent) {
    CallbackContext cb = mScanStatusCallback;
    if (cb == null)
        return;/* w ww  . j  a va  2s .  c om*/

    String event;
    String action = intent.getAction();

    if (action.equals(RfidConstants.ACTION_RFID_START_SCAN_NOTIFICATION)) {
        event = EVENT_SCAN_STARTED;
    } else if (action.equals(RfidConstants.ACTION_RFID_STOP_SCAN_NOTIFICATION)) {
        event = EVENT_SCAN_STOPPED;
    } else {
        return;
    }

    PluginResult result = new PluginResult(PluginResult.Status.OK, event);
    result.setKeepCallback(true);
    cb.sendPluginResult(result);
}

From source file:com.tt.jobtracker.MainActivity.java

private void handleIntent(Intent intent) {
    setContentView(R.layout.activity_main);
    SetNavigationDrawer();/*from   w w  w . ja  v  a  2 s. co m*/

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        SearchText = intent.getStringExtra(SearchManager.QUERY);
    } else {
        SearchText = "";
    }
}

From source file:com.ubuntuone.android.files.service.MetaService.java

@Override
protected void onHandleIntent(Intent intent) {
    sSyncRunning = true;/*from  w w  w .j  av a 2s .  co  m*/
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

    final String action = intent.getAction();
    final String resourcePath = intent.getStringExtra(EXTRA_RESOURCE_PATH);
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_CALLBACK);

    if (ACTION_GET_USER.equals(action)) {
        getUser(receiver);
        getVolumes(receiver);
    } else if (ACTION_GET_VOLUME.equals(action)) {
        getVolume(resourcePath, receiver);
    } else if (ACTION_CREATE_VOLUME.equals(action)) {
        createVolume(resourcePath, receiver);
    } else if (ACTION_MAKE_DIRECTORY.equals(action)) {
        makeDirectory(resourcePath, receiver);
    } else if (ACTION_GET_NODE.equals(action)) {
        getNode(resourcePath, receiver, true);
    } else if (ACTION_UPDATE_NODE.equals(action)) {
        if (intent.hasExtra(Nodes.NODE_NAME)) {
            String newPath = intent.getStringExtra(EXTRA_PATH);
            updateNode(resourcePath, newPath, receiver);
        }
        if (intent.hasExtra(Nodes.NODE_IS_PUBLIC)) {
            Boolean isPublic = intent.getBooleanExtra(Nodes.NODE_IS_PUBLIC, false);
            updateNode(resourcePath, isPublic, receiver);
        }
    } else if (ACTION_DELETE_NODE.equals(action)) {
        deleteNode(resourcePath, receiver);
    }
    sSyncRunning = false;
}

From source file:com.connectsdk.discovery.DiscoveryManager.java

/**
 * Create a new instance of DiscoveryManager.
 * Direct use of this constructor is not recommended. In most cases,
 * you should use DiscoveryManager.getInstance() instead.
 *//*from   w ww  .j  av  a  2  s. co m*/
public DiscoveryManager(Context context, ConnectableDeviceStore connectableDeviceStore) {
    this.context = context;
    this.connectableDeviceStore = connectableDeviceStore;

    allDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);
    compatibleDevices = new ConcurrentHashMap<String, ConnectableDevice>(8, 0.75f, 2);

    deviceClasses = new ConcurrentHashMap<String, Class<? extends DeviceService>>(4, 0.75f, 2);
    discoveryProviders = new CopyOnWriteArrayList<DiscoveryProvider>();

    discoveryListeners = new CopyOnWriteArrayList<DiscoveryManagerListener>();

    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    multicastLock = wifiMgr.createMulticastLock("Connect SDK");
    multicastLock.setReferenceCounted(true);

    capabilityFilters = new ArrayList<CapabilityFilter>();
    pairingLevel = PairingLevel.OFF;

    receiver = new BroadcastReceiver() {

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

            if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

                switch (networkInfo.getState()) {
                case CONNECTED:
                    if (mSearching) {
                        for (DiscoveryProvider provider : discoveryProviders) {
                            provider.start();
                        }
                    }

                    break;

                case DISCONNECTED:
                    Log.w("Connect SDK", "Network connection is disconnected");

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.reset();
                    }

                    allDevices.clear();

                    for (ConnectableDevice device : compatibleDevices.values()) {
                        handleDeviceLoss(device);
                    }
                    compatibleDevices.clear();

                    for (DiscoveryProvider provider : discoveryProviders) {
                        provider.stop();
                    }

                    break;

                case CONNECTING:
                    break;
                case DISCONNECTING:
                    break;
                case SUSPENDED:
                    break;
                case UNKNOWN:
                    break;
                }
            }
        }
    };

    registerBroadcastReceiver();
}

From source file:edu.mit.mobile.android.locast.sync.MediaSync.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) {
            enqueueUnpublishedMedia();/*w  w  w . j a  v  a  2  s  . c o m*/

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

    return START_REDELIVER_INTENT;
}