List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:com.wojtechnology.sunami.TheBrain.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent.getAction(); if (mIsInit && action != null) { switch (intent.getAction()) { case TOGGLE_PLAY: togglePlay();/*w ww.j a va 2 s . c o m*/ break; case PLAY_NEXT: playNext(); break; case PLAY_LAST: playLast(); break; case PLAY_STOP: pausePlayback(); unregisterAudio(); stopForeground(true); if (mBound) { mContext.updateSongView(); } else { mContext.serviceFinished(); mMediaPlayer.release(); stopSelf(); } break; case UPDATE_SETTINGS: mMainPrefs.updateValues(); mShuffleController.updateValues(); break; default: break; } } return START_NOT_STICKY; }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
public void loadFromIntents() { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); System.out.println("Intentoso " + action + " type " + type); if (Intent.ACTION_SEND.equals(action) && type != null) { if (type.startsWith("image/")) { setBackgroundUri((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); }//from w ww. j a va 2 s . c o m } }
From source file:at.jclehner.rxdroid.DrugEditFragment.java
public void onBackPressed() { final Intent intent = getActivity().getIntent(); final String action = intent.getAction(); final Drug drug = mWrapper.get(); final String drugName = drug.getName(); if (drugName == null || drugName.length() == 0) { showDrugDiscardDialog();//w w w . ja va 2 s .co m return; } if (Intent.ACTION_EDIT.equals(action)) { if (mDrugHash != drug.hashCode()) { if (LOGV) Util.dumpObjectMembers(TAG, Log.VERBOSE, drug, "drug 2"); showSaveChangesDialog(); return; } } else if (Intent.ACTION_INSERT.equals(action)) { Database.create(drug, 0); Toast.makeText(getActivity(), getString(R.string._toast_saved), Toast.LENGTH_SHORT).show(); } getActivity().finish(); }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
private void registerAudioManagerReceiver() { IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); audioManagerReceiver = new BroadcastReceiver() { @Override//from w w w. j a v a 2 s. co m public void onReceive(Context context, Intent intent) { if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { // Pause playback pause(); } } }; registerReceiver(audioManagerReceiver, filter); }
From source file:com.heneryh.aquanotes.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")"); /**// w ww.j a v a2 s. co m * Using the intent, we can tell why we are running this service */ Cursor cursor = null; // This came from the timer expiring or from the gui, either way, push all controllers onto the queue. if (ACTION_UPDATE_ALL.equals(intent.getAction()) || Intent.ACTION_SYNC.equals(intent.getAction())) { try { Uri controllersQueryUri = Controllers.buildQueryControllersUri(); cursor = dbResolverSyncSrvc.query(controllersQueryUri, ControllersQuery.PROJECTION, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { Integer controllerId = cursor.getInt(ControllersQuery._ID); requestUpdate(controllerId); cursor.moveToNext(); } } } catch (SQLException e) { Log.e(TAG, "getting controller list", e); // need a little more here! } finally { if (cursor != null) { cursor.close(); } } } else if (ACTION_UPDATE_SINGLE.equals(intent.getAction())) { // This came from the a widget update, id is in the queue } /** * Only start processing thread if not already running, if the thread was running it would * grab the queue items */ synchronized (sLock) { if (!sThreadRunning) { sThreadRunning = true; new SyncThread().execute(); } } }
From source file:edu.mit.mobile.android.locast.data.Sync.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { if (Intent.ACTION_SYNC.equals(intent.getAction())) { if (intent.getBooleanExtra(EXTRA_EXPLICIT_SYNC, false)) { mNotifiedUserAboutNetworkStatus = true; mShouldAlertUserOnSuccess = true; }/*from w w w . ja v a 2s .c o m*/ startSync(intent.getData(), intent.getExtras()); } else if (ACTION_CANCEL_SYNC.equals(intent.getAction())) { stopSync(); } } else { // restarted by system. startSync(); } return START_NOT_STICKY; }
From source file:at.jclehner.rxdroid.DrugEditFragment.java
@Override public void onResume() { super.onResume(); Intent intent = getActivity().getIntent(); String action = intent.getAction(); Drug drug = null;//from www .j a va 2s .c o m mWrapper = new DrugWrapper(); mFocusOnCurrentSupply = false; if (Intent.ACTION_EDIT.equals(action)) { final int drugId = intent.getIntExtra(DrugEditActivity2.EXTRA_DRUG_ID, -1); if (drugId == -1) throw new IllegalStateException("ACTION_EDIT requires EXTRA_DRUG_ID"); drug = Drug.get(drugId); if (LOGV) Util.dumpObjectMembers(TAG, Log.VERBOSE, drug, "drug"); mWrapper.set(drug); mDrugHash = drug.hashCode(); mIsEditing = true; if (intent.getBooleanExtra(DrugEditActivity2.EXTRA_FOCUS_ON_CURRENT_SUPPLY, false)) mFocusOnCurrentSupply = true; setActivityTitle(drug.getName()); } else if (Intent.ACTION_INSERT.equals(action)) { mIsEditing = false; mWrapper.set(new Drug()); setActivityTitle(R.string._title_new_drug); } else throw new IllegalArgumentException("Unhandled action " + action); if (mWrapper.refillSize == 0) mWrapper.currentSupply = Fraction.ZERO; OTPM.mapToPreferenceHierarchy(getPreferenceScreen(), mWrapper); getPreferenceScreen().setOnPreferenceChangeListener(mListener); if (!mIsEditing) { final Preference p = findPreference("active"); if (p != null) p.setEnabled(false); } if (mWrapper.refillSize == 0) { final Preference p = findPreference("currentSupply"); if (p != null) p.setEnabled(false); } if (mFocusOnCurrentSupply) { Log.i(TAG, "Will focus on current supply preference"); performPreferenceClick("currentSupply"); } getActivity().supportInvalidateOptionsMenu(); }
From source file:com.taw.gotothere.GoToThereActivity.java
/** * Handle any intents passed into the activity. Currently we only deal with * on, ACTION_SEARCH, which means we've been given a query string to search * for via the quick search box. We'll also handle the case where the activity * is restarted due to orientation changes; in this situation we still have the * intent with ACTION_SEARCH, so we check if we've already processed it; if so * don't bother geocoding.// www . ja v a2 s . c o m * * @param intent The intent to process * @param savedInstanceState The bundle passed into the activity on (re)start */ private void handleIntent(Intent intent, Bundle savedInstanceState) { if (intent.getAction().equals(Intent.ACTION_SEARCH)) { Log.d(TAG, "Started as a result of ACTION_SEARCH"); String query = intent.getStringExtra(SearchManager.QUERY); SharedPreferences prefs = getPreferences(Activity.MODE_PRIVATE); String previousQuery = prefs.getString(PREVIOUS_QUERY, null); if (previousQuery == null || !previousQuery.equals(query)) { Log.d(TAG, " Haven't processed this query before"); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, GoToThereSuggestionProvider.AUTHORITY, GoToThereSuggestionProvider.MODE); suggestions.saveRecentQuery(query, null); geocodeResult(query); } // Else UI stuff set up by onRestoreInstanceState() } }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { String action = intent.getAction(); if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF); if (state == BluetoothAdapter.STATE_ON) { if (mStartedBT) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth enabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); }//from w w w. j av a 2 s . c o m } if ((mQueueAddress != null) && (mQueueState != null)) requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); else if (mRequestDiscovery && !mBtAdapter.isDiscovering()) mBtAdapter.startDiscovery(); else if (mUIInterface != null) { try { mUIInterface.setBluetoothEnabled(); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } } else if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (mUIInterface != null) { try { mUIInterface.setMessage("Bluetooth disabled"); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } stopThreads(); } } else if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device.getBondState() == BluetoothDevice.BOND_BONDED) { // connect if configured String address = device.getAddress(); for (JSONObject deviceJObj : mDevices) { try { if (deviceJObj.getString(KEY_ADDRESS).equals(address)) { // if queued mDeviceFound = (mQueueAddress != null) && mQueueAddress.equals(address) && (mQueueState != null); break; } } catch (JSONException e) { Log.e(TAG, e.getMessage()); } } } else if (mRequestDiscovery && (mUIInterface != null)) { String unpairedDevice = TapLock .createDevice(device.getName(), device.getAddress(), DEFAULT_PASSPHRASE).toString(); try { mUIInterface.setUnpairedDevice(unpairedDevice); } catch (RemoteException e) { Log.e(TAG, e.getMessage()); } } } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { if (mDeviceFound) { requestWrite(mQueueAddress, mQueueState, mQueuePassphrase); mDeviceFound = false; } else if (mRequestDiscovery) { mRequestDiscovery = false; if (mUIInterface != null) { try { mUIInterface.setDiscoveryFinished(); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } } } else if (ACTION_TOGGLE.equals(action) && intent.hasExtra(EXTRA_DEVICE_ADDRESS)) { String address = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); requestWrite(address, ACTION_TOGGLE, null); } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { // create widget if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (intent.hasExtra(EXTRA_DEVICE_NAME)) { // add a widget String deviceName = intent.getStringExtra(EXTRA_DEVICE_NAME); for (int i = 0, l = mDevices.size(); i < l; i++) { String name = null; try { name = mDevices.get(i).getString(KEY_NAME); } catch (JSONException e1) { e1.printStackTrace(); } if ((name != null) && name.equals(deviceName)) { JSONObject deviceJObj = mDevices.remove(i); JSONArray widgetsJArr; if (deviceJObj.has(KEY_WIDGETS)) { try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { widgetsJArr = new JSONArray(); } } else widgetsJArr = new JSONArray(); widgetsJArr.put(appWidgetId); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); } catch (JSONException e) { e.printStackTrace(); } mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); break; } } } buildWidget(appWidgetId); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { for (int appWidgetId : appWidgetIds) buildWidget(appWidgetId); } } } else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); Log.d(TAG, "delete appWidgetId: " + appWidgetId); for (int i = 0, l = mDevices.size(); i < l; i++) { JSONObject deviceJObj = mDevices.get(i); if (deviceJObj.has(KEY_WIDGETS)) { JSONArray widgetsJArr = null; try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { e.printStackTrace(); } if (widgetsJArr != null) { boolean wasUpdated = false; JSONArray newWidgetsJArr = new JSONArray(); for (int widgetIdx = 0, wdigetsLen = widgetsJArr .length(); widgetIdx < wdigetsLen; widgetIdx++) { int widgetId; try { widgetId = widgetsJArr.getInt(widgetIdx); } catch (JSONException e) { widgetId = AppWidgetManager.INVALID_APPWIDGET_ID; e.printStackTrace(); } Log.d(TAG, "eval widgetId: " + widgetId); if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (widgetId == appWidgetId)) { Log.d(TAG, "skip: " + widgetId); wasUpdated = true; } else { Log.d(TAG, "include: " + widgetId); newWidgetsJArr.put(widgetId); } } if (wasUpdated) { try { deviceJObj.put(KEY_WIDGETS, newWidgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); Log.d(TAG, "stored: " + deviceJObj.toString()); } catch (JSONException e) { e.printStackTrace(); } } } } else { JSONArray widgetsJArr = new JSONArray(); try { deviceJObj.put(KEY_WIDGETS, widgetsJArr); mDevices.remove(i); mDevices.add(i, deviceJObj); TapLock.storeDevices(this, getSharedPreferences(KEY_PREFS, MODE_PRIVATE), mDevices); } catch (JSONException e) { e.printStackTrace(); } } } } } return START_STICKY; }
From source file:com.browsertophone.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras();//from ww w . j a va 2 s. com if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); if (debug != null) { // server-controlled debug - the server wants to know // we received the message, and when. This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get); } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel); // Notify and optionally start activity if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { LauncherUtils.playNotificationSound(context); context.startActivity(launchIntent); } else { if (sel != null && sel.length() > 0) { // have selection LauncherUtils.generateNotification(context, sel, context.getString(R.string.copied_desktop_clipboard), launchIntent); } else { LauncherUtils.generateNotification(context, url, title, launchIntent); } } // Record history (for link/maps only) if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) { HistoryDatabase.get(context).insertHistory(title, url); } } } }