List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:ack.me.truconnectandroiddemo.DeviceInfoActivity.java
private void initBroadcastReceiver() { mBroadcastReceiver = new BroadcastReceiver() { @Override/*from w w w . ja v a 2 s . com*/ public void onReceive(Context context, Intent intent) { // Get extra data included in the Intent String action = intent.getAction(); switch (action) { case TruconnectService.ACTION_COMMAND_SENT: String command = TruconnectService.getCommand(intent).toString(); Log.d(TAG, "Command " + command + " sent"); break; case TruconnectService.ACTION_COMMAND_RESULT: handleCommandResponse(intent); break; case TruconnectService.ACTION_ERROR: TruconnectErrorCode errorCode = TruconnectService.getErrorCode(intent); //handle errors break; case TruconnectService.ACTION_DISCONNECTED: mDisconnectDialog.dismiss(); finish(); break; } } }; }
From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java
public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;//from w w w . jav a2 s . c o m } if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0)); Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); if (intent == null) { return; } // This name is only used for comparisons and notifications, so fall // back to activity name // if not supplied String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return; } } Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Queue the item up for adding if launcher has not loaded properly yet LauncherAppState.setApplicationContext(context.getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); boolean launcherNotLoaded = (app.getDynamicGrid() == null); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info); if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }
From source file:com.piusvelte.taplock.client.core.TapLockToggle.java
@Override public void onServiceConnected(ComponentName name, IBinder binder) { mServiceInterface = ITapLockService.Stub.asInterface(binder); if (mUIInterface != null) { try {/*from ww w.j a v a2s . c om*/ mServiceInterface.setCallback(mUIInterface); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } Intent intent = getIntent(); if (intent != null) { String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action) && intent.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { Log.d(TAG, "service connected, NDEF_DISCOVERED"); Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage message; if (rawMsgs != null) { // process the first message message = (NdefMessage) rawMsgs[0]; // process the first record NdefRecord record = message.getRecords()[0]; if (record.getTnf() == NdefRecord.TNF_WELL_KNOWN) { try { byte[] payload = record.getPayload(); /* * payload[0] contains the "Status Byte Encodings" field, per the * NFC Forum "Text Record Type Definition" section 3.2.1. * * bit7 is the Text Encoding Field. * * if (Bit_7 == 0): The text is encoded in UTF-8 if (Bit_7 == 1): * The text is encoded in UTF16 * * Bit_6 is reserved for future use and must be set to zero. * * Bits 5 to 0 are the length of the IANA language code. */ String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16"; int languageCodeLength = payload[0] & 0077; String taggedDeviceName = new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding); manageDevice(taggedDeviceName, ACTION_TOGGLE); } catch (UnsupportedEncodingException e) { // should never happen unless we get a malformed tag. Log.e(TAG, e.toString()); finish(); } } else finish(); } else finish(); } else if (intent.getData() != null) { String taggedDeviceName = intent.getData().getHost(); if (taggedDeviceName != null) manageDevice(taggedDeviceName, ACTION_TOGGLE); else finish(); } else if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action)) manageDevice(intent.getStringExtra(EXTRA_DEVICE_NAME), action); else finish(); } else finish(); }
From source file:com.inbeacon.cordova.CordovaInbeaconManager.java
/** * Transform Android event data into JSON Object used by JavaScript * @param intent inBeacon SDK event data * @return a JSONObject with keys 'event', 'name' and 'data' *//*from w w w .j a v a 2s . com*/ private JSONObject getEventObject(Intent intent) { String action = intent.getAction(); String event = action.substring(action.lastIndexOf(".") + 1); // last part of action String message = intent.getStringExtra("message"); Bundle extras = intent.getExtras(); JSONObject eventObject = new JSONObject(); JSONObject data = new JSONObject(); try { if (extras != null) { Set<String> keys = extras.keySet(); for (String key : keys) { data.put(key, extras.get(key)); // Android API < 19 // data.put(key, JSONObject.wrap(extras.get(key))); // Android API >= 19 } } data.put("message", message); eventObject.put("name", event); eventObject.put("data", data); } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); } return eventObject; }
From source file:com.sym.demozxing.zxing.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 || !Intents.SearchBookContents.ACTION.equals(intent.getAction())) { finish();/*from ww w. j av a 2 s.com*/ 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:androidx.media.MediaSessionService2.java
/** * Default implementation for {@link MediaSessionService2} to handle incoming binding * request. If the request is for getting the session, the intent will have action * {@link #SERVICE_INTERFACE}./*www . j a va 2 s .c om*/ * <p> * Override this method if this service also needs to handle binder requests other than * {@link #SERVICE_INTERFACE}. Derived classes MUST call through to the super class's * implementation of this method. * * @param intent * @return Binder */ @CallSuper @Nullable @Override public IBinder onBind(Intent intent) { if (MediaSessionService2.SERVICE_INTERFACE.equals(intent.getAction()) || MediaBrowserServiceCompat.SERVICE_INTERFACE.equals(intent.getAction())) { // Change the intent action for browser service. Intent browserServiceIntent = new Intent(intent); browserServiceIntent.setAction(MediaSessionService2.SERVICE_INTERFACE); return mBrowserServiceCompat.onBind(intent); } return null; }
From source file:com.google.zxing.client.android.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) && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) { finish();/*from ww w .ja va 2s. c o m*/ return; } mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN); setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN); setContentView(R.layout.search_book_contents); mQueryTextView = (EditText) findViewById(R.id.query_text_view); String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY); if (initialQuery != null && initialQuery.length() > 0) { // Populate the search box but don't trigger the search mQueryTextView.setText(initialQuery); } mQueryTextView.setOnKeyListener(mKeyListener); mQueryButton = (Button) findViewById(R.id.query_button); mQueryButton.setOnClickListener(mButtonListener); mResultListView = (ListView) findViewById(R.id.result_list_view); LayoutInflater factory = LayoutInflater.from(this); mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false); mResultListView.addHeaderView(mHeaderView); mUserAgent = getString(R.string.zxing_user_agent); }
From source file:io.ionic.links.IonicDeeplink.java
public void handleIntent(Intent intent) { final String intentString = intent.getDataString(); // read intent String action = intent.getAction(); Uri url = intent.getData();//from w w w .ja v a 2 s . co m JSONObject bundleData = this._bundleToJson(intent.getExtras()); Log.d(TAG, "Got a new intent: " + intentString + " " + intent.getScheme() + " " + action + " " + url); // if app was not launched by the url - ignore if (!Intent.ACTION_VIEW.equals(action) || url == null) { return; } // store message and try to consume it try { lastEvent = new JSONObject(); lastEvent.put("url", url.toString()); lastEvent.put("path", url.getPath()); lastEvent.put("queryString", url.getQuery()); lastEvent.put("scheme", url.getScheme()); lastEvent.put("host", url.getHost()); lastEvent.put("fragment", url.getFragment()); lastEvent.put("extra", bundleData); consumeEvents(); } catch (JSONException ex) { Log.e(TAG, "Unable to process URL scheme deeplink", ex); } }
From source file:net.reichholf.dreamdroid.activities.DreamDroidShareActivity.java
@SuppressWarnings("deprecation") private void playOnDream(Profile p) { String url = null;//from w w w. j ava 2 s .co m Intent i = getIntent(); Bundle extras = i.getExtras(); mShc = SimpleHttpClient.getInstance(p); if (Intent.ACTION_SEND.equals(i.getAction())) url = extras.getString(Intent.EXTRA_TEXT); else if (Intent.ACTION_VIEW.equals(i.getAction())) url = i.getDataString(); if (url != null) { Log.i(LOG_TAG, url); Log.i(LOG_TAG, p.getHost()); String time = DateFormat.getDateFormat(this).format(new Date()); String title = getString(R.string.sent_from_dreamdroid, time); if (extras != null) { // semperVidLinks sends "artist" and "song" attributes for the // youtube video titles String song = extras.getString("song"); if (song != null) { String artist = extras.getString("artist"); if (artist != null) title = artist + " - " + song; } else { String tmp = extras.getString("title"); if (tmp != null) title = tmp; } } mTitle = new String(title); url = URLEncoder.encode(url).replace("+", "%20"); title = URLEncoder.encode(title).replace("+", "%20"); String ref = "4097:0:1:0:0:0:0:0:0:0:" + url + ":" + title; Log.i(LOG_TAG, ref); ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("file", ref)); execSimpleResultTask(params); } else { finish(); } }
From source file:com.androidrocks.bex.zxing.client.android.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) && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) { finish();/*from w w w .j a v a 2s . c om*/ return; } mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN); setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN); setContentView(R.layout.search_book_contents); mQueryTextView = (EditText) findViewById(R.id.query_text_view); String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY); if (initialQuery != null && initialQuery.length() > 0) { // Populate the search box but don't trigger the search mQueryTextView.setText(initialQuery); } mQueryTextView.setOnKeyListener(mKeyListener); mQueryButton = (Button) findViewById(R.id.query_button); mQueryButton.setOnClickListener(mButtonListener); mResultListView = (ListView) findViewById(R.id.result_list_view); LayoutInflater factory = LayoutInflater.from(this); mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false); mResultListView.addHeaderView(mHeaderView); }