List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:edu.cmu.plugins.PhoneListener.java
/** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. * // ww w .jav a 2 s . c o m * @param ctx The context of the main Activity. */ public void setContext(PhonegapActivity ctx) { super.setContext(ctx); this.phoneListenerCallbackId = null; // We need to listen to connectivity events to update navigator.connection IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED"); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent == null) { return; } String state = ""; if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { state = "SMS_RECEIVED"; Log.i(LOG_TAG, state); } if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { // State has changed String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE) ? intent.getStringExtra(TelephonyManager.EXTRA_STATE) : null; // See if the new state is 'ringing', 'off hook' or 'idle' if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) { // phone is ringing, awaiting either answering or canceling state = "RINGING"; Log.i(LOG_TAG, state); } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { // actually talking on the phone... either making a call or having answered one state = "OFFHOOK"; Log.i(LOG_TAG, state); } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) { // idle means back to no calls in or out. default state. state = "IDLE"; Log.i(LOG_TAG, state); } else { state = TYPE_NONE; Log.i(LOG_TAG, state); } } updatePhoneState(state, true); } }; // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml ctx.registerReceiver(this.receiver, intentFilter); } }
From source file:org.mrquiz.android.tinyurl.SendTinyUrlActivity.java
private void send() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); Intent originalIntent = getIntent(); if (Intent.ACTION_SEND.equals(originalIntent.getAction())) { // Copy extras from the original intent because they miht contain // additional information about the URL (e.g., the title of a // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid // overwriting the TinyShare. intent.putExtras(originalIntent.getExtras()); }/*ww w . j a v a 2s . c o m*/ intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl); try { CharSequence template = getText(R.string.title_send); String title = String.format(String.valueOf(template), mTinyUrl); startActivity(Intent.createChooser(intent, title)); } catch (ActivityNotFoundException e) { handleError(e); } }
From source file:alaindc.crowdroid.View.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listGeofenceCircle = new HashMap<>(); listCircles = new HashMap<>(); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); textView = (TextView) findViewById(R.id.textView); textView.setMovementMethod(new ScrollingMovementMethod()); sensorsCheckbox = (CheckBox) findViewById(R.id.sensorscheck); requestsCheckbox = (CheckBox) findViewById(R.id.requestscheck); this.settingsButton = (Button) findViewById(R.id.settbutton); settingsButton.setOnClickListener(new View.OnClickListener() { @Override//www. j av a2 s. c o m public void onClick(View v) { Intent i = new Intent(getApplicationContext(), StakeholdersActivity.class); startActivity(i); } }); this.requestButton = (Button) findViewById(R.id.button); requestButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO: Disable //requestButton.setEnabled(false); // Start sending messages to server Intent serviceIntent[] = new Intent[Constants.MONITORED_SENSORS.length]; for (int i = 0; i < Constants.MONITORED_SENSORS.length; i++) { serviceIntent[i] = new Intent(getApplicationContext(), SendIntentService.class); serviceIntent[i].setAction(Constants.ACTION_SENDDATA + Constants.MONITORED_SENSORS[i]); serviceIntent[i].putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND, Constants.MONITORED_SENSORS[i]); // TODO Here set to send all kind of sensor for start getApplicationContext().startService(serviceIntent[i]); } } }); this.sensorButton = (Button) findViewById(R.id.buttonLoc); sensorButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { sensorButton.setEnabled(false); // Clear preferences getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE).edit().clear().commit(); // Start service for PhoneListener Intent phoneListIntent = new Intent(getApplicationContext(), NeverSleepService.class); getApplicationContext().startService(phoneListIntent); // Start intent service for update position Intent posintent = new Intent(getApplicationContext(), PositionIntentService.class); getApplicationContext().startService(posintent); // Start intent service for update sensors Intent sensorintent = new Intent(getApplicationContext(), SensorsIntentService.class); sensorintent.setAction(Constants.INTENT_START_SENSORS); getApplicationContext().startService(sensorintent); // Start intent service for update amplitude sensing Intent amplintent = new Intent(getApplicationContext(), SensorsIntentService.class); amplintent.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE); getApplicationContext().startService(amplintent); } }); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENT_RECEIVED_DATA)) { String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA); if (response != null && requestsCheckbox.isChecked()) textView.append(response + "\n"); } else if (intent.getAction().equals(Constants.INTENT_UPDATE_POS)) { setLocationAndMap(); } else if (intent.getAction().equals(Constants.INTENT_UPDATE_SENSORS)) { String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA); if (response != null && sensorsCheckbox.isChecked()) textView.append(response + "\n"); } else if (intent.getAction().equals(Constants.INTENT_UPDATE_GEOFENCEVIEW)) { // Geofencing addGeofenceView(intent.getIntExtra(Constants.INTENT_GEOFENCEEXTRA_SENSOR, 0), intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LATITUDE, 0), intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LONGITUDE, 0), intent.getFloatExtra(Constants.INTENT_GEOFENCEEXTRA_RADIUS, 100)); } else { Log.d("", ""); } } }; IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENT_RECEIVED_DATA); IntentFilter updatePosIntFilter = new IntentFilter(Constants.INTENT_UPDATE_POS); IntentFilter updateSenseIntFilter = new IntentFilter(Constants.INTENT_UPDATE_SENSORS); IntentFilter updateGeofenceViewIntFilter = new IntentFilter(Constants.INTENT_UPDATE_GEOFENCEVIEW); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updatePosIntFilter); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateSenseIntFilter); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateGeofenceViewIntFilter); }
From source file:br.com.devfest.norte.wear.HomeListenerService.java
public int onStartCommand(Intent intent, int flags, int startId) { LOGD(TAG, "onStartCommand"); if (null != intent) { String action = intent.getAction(); if (ACTION_DISMISS.equals(action)) { String sessionId = intent.getStringExtra(KEY_SESSION_ID); LOGD(TAG, "onStartCommand(): Action: ACTION_DISMISS Session: " + sessionId); dismissPhoneNotification(sessionId); } else if (ACTION_START_FEEDBACK.equals(action)) { Intent feedbackIntent = new Intent(this, PagerActivity.class); String sessionId = intent.getStringExtra(HomeListenerService.KEY_SESSION_ID); LOGD(TAG, "Received session id from data layer: " + sessionId); feedbackIntent.putExtra(HomeListenerService.KEY_SESSION_ID, sessionId); feedbackIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(feedbackIntent); NotificationManagerCompat.from(this).cancel(NOTIFICATION_ID); }//from w w w. jav a 2s. c o m } return Service.START_NOT_STICKY; }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;/*from ww w.j av a 2s .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:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java
@Test public void test_Intents() { // Launch activity with ACTION_SEARCH intent and then trigger new ACTION_VIEW intent // Launch activity Intent intent = getNewIntent();//from w w w . jav a2 s . co m intent.setAction(Intent.ACTION_SEARCH); intent.putExtra(SearchManager.QUERY, SEARCH_TEXT); createWithIntent(intent); // Verify onCreate() resulted in LoaderCallbacks object being created assertThat(titleSearchResultsActivity.loaderCallbacks).isNotNull(); // Verify LoaderManager restartLoader called with correct search term ArgumentCaptor<Bundle> arguments = ArgumentCaptor.forClass(Bundle.class); verify(loaderManager).restartLoader(eq(0), arguments.capture(), eq(titleSearchResultsActivity.loaderCallbacks)); assertThat(arguments.getValue().containsKey("QUERY_TEXT_KEY")); assertThat(arguments.getValue().get("QUERY_TEXT_KEY")).isEqualTo(SEARCH_TEXT); // Verify setOnItemClickListener called on view verify(listView).setOnItemClickListener(isA(OnItemClickListener.class)); // Verify Loader constructor arguments have correct details SuggestionCursorParameters params = new SuggestionCursorParameters(arguments.getValue(), ClassyFySearchEngine.LEX_CONTENT_URI, 50); assertThat(params.getUri()) .isEqualTo(Uri.parse("content://au.com.cybersearch2.classyfy.ClassyFyProvider/lex/" + SearchManager.SUGGEST_URI_PATH_QUERY)); assertThat(params.getProjection()).isNull(); assertThat(params.getSelection()).isEqualTo("word MATCH ?"); assertThat(params.getSelectionArgs()).isEqualTo(new String[] { SEARCH_TEXT }); assertThat(params.getSortOrder()).isNull(); // Verify Loader callbacks in sequence onCreateLoader, onLoadFinished and onLoaderReset CursorLoader cursorLoader = (CursorLoader) titleSearchResultsActivity.loaderCallbacks.onCreateLoader(0, arguments.getValue()); Cursor cursor = mock(Cursor.class); titleSearchResultsActivity.loaderCallbacks.onLoadFinished(cursorLoader, cursor); verify(simpleCursorAdapter).swapCursor(cursor); titleSearchResultsActivity.loaderCallbacks.onLoaderReset(cursorLoader); verify(simpleCursorAdapter).swapCursor(null); // Trigger new ACTION_VIEW intent and confirm MainActivity started with ACTION_VIEW intent intent = getNewIntent(); intent.setAction(Intent.ACTION_VIEW); Uri actionUri = Uri.withAppendedPath(ClassyFySearchEngine.CONTENT_URI, "44"); intent.setData(actionUri); titleSearchResultsActivity.onNewIntent(intent); ShadowActivity shadowActivity = Robolectric.shadowOf(titleSearchResultsActivity); Intent startedIntent = shadowActivity.getNextStartedActivity(); assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(startedIntent.getData()).isEqualTo(actionUri); ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent); assertThat(shadowIntent.getComponent().getClassName()) .isEqualTo("au.com.cybersearch2.classyfy.MainActivity"); }
From source file:com.bluros.updater.service.UpdateCheckService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (TextUtils.equals(intent.getAction(), ACTION_CANCEL_CHECK)) { ((UpdateApplication) getApplicationContext()).getQueue().cancelAll(TAG); return START_NOT_STICKY; }//w w w.j a va2 s . c om return super.onStartCommand(intent, flags, startId); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.service.OrgSyncService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction() != null && ACTION_PAUSE.equals(intent.getAction())) { pause();/*w w w.j a v a2s .com*/ } else { final Message msg = serviceHandler.obtainMessage(); msg.arg1 = TWO_WAY_SYNC; serviceHandler.sendMessage(msg); } // If we get killed, after returning from here, restart return START_STICKY; }
From source file:com.android.gallery3d.app.Gallery.java
private void initializeByIntent() { Intent intent = getIntent(); String action = intent.getAction(); if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)) { startGetContent(intent);/*www . j a va2s . c o m*/ } else if (Intent.ACTION_PICK.equalsIgnoreCase(action)) { // We do NOT really support the PICK intent. Handle it as // the GET_CONTENT. However, we need to translate the type // in the intent here. Log.w(TAG, "action PICK is not supported"); String type = Utils.ensureNotNull(intent.getType()); if (type.startsWith("vnd.android.cursor.dir/")) { if (type.endsWith("/image")) intent.setType("image/*"); if (type.endsWith("/video")) intent.setType("video/*"); } startGetContent(intent); } else if (Intent.ACTION_VIEW.equalsIgnoreCase(action) || ACTION_REVIEW.equalsIgnoreCase(action)) { startViewAction(intent); } else { startDefaultPage(); } }
From source file:com.llf.android.launcher3.InstallShortcutReceiver.java
@Override public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;/*from w w w. j av a 2 s.com*/ } 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); } }