List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java
private void speechToText() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault()); try {/*from w w w .j a v a 2s . c o m*/ if (intent.resolveActivity(getActivity().getPackageManager()) == null) { AlfrescoNotificationManager.getInstance(getActivity()).showAlertCrouton(getActivity(), getString(R.string.feature_disable)); return; } startActivityForResult(intent, RequestCode.TEXT_TO_SPEECH); } catch (ActivityNotFoundException a) { AlfrescoNotificationManager.getInstance(getActivity()).showToast(R.string.file_editor_error_speech); } }
From source file:com.example.android.shuttershock.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }// w w w . j a v a 2s . c o m // Handle action buttons switch (item.getItemId()) { case R.id.take_pic: Toast.makeText(getApplicationContext(), "button is working", Toast.LENGTH_LONG).show(); takePic(); //galleryAddPic(); return true; case R.id.upload: /* Intent intentx = new Intent(); intentx.setType("image/*"); intentx.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult( Intent.createChooser(intentx, "Select Picture"), SELECT_PICTURE);*/ final Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, SELECT_PICTURE); //galleryAddPic(); return true; case R.id.look: LongOperation longOperation = new LongOperation(this); longOperation.execute(); // readContacts(); return true; case R.id.action_websearch: // create intent to perform web search for this filter Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
/** * take picture//from w w w . j a v a 2 s.c o m */ public void takePicture(Fragment fragment, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getActivity()); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath()); } } fragment.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.example.android.pharmacyinventory.EditorActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) { // Bail early if the cursor is null or there is less than 1 row in the cursor if (cursor == null || cursor.getCount() < 1) { return;//w w w.j av a 2 s .c o m } // Proceed with moving to the first row of the cursor and reading data from it // (This should be the only row in the cursor) if (cursor.moveToFirst()) { // Find the columns of drug attributes that we're interested in int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME); int quantityColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_QUANTITY); int priceColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_PRICE); int imageColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_IMAGE); // Extract out the value from the Cursor for the given column index String name = cursor.getString(nameColumnIndex); int quantity = cursor.getInt(quantityColumnIndex); Double price = cursor.getDouble(priceColumnIndex); String picture = cursor.getString(imageColumnIndex); // Update the views on the screen with the values from the database mNameEditText.setText(name); mQuantityText.setText(Integer.toString(quantity)); mPriceEditText.setText(Double.toString(price)); mDrugImage.setImageURI(Uri.parse(picture)); } orderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Get the Uri for the current drug int IdColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry._ID); final long itemId = cursor.getLong(IdColumnIndex); Uri mCurrentDrugUri = ContentUris.withAppendedId(DrugContract.DrugEntry.CONTENT_URI, itemId); // Find the columns of drug attributes that we're interested in int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME); // Read the Drug attributes from the Cursor for the current drug String name = cursor.getString(nameColumnIndex); // Read the drug name to use in subject line String subjectLine = "Need to order: " + name; Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle this intent.putExtra(Intent.EXTRA_EMAIL, "orders@gmail.com"); intent.putExtra(Intent.EXTRA_SUBJECT, subjectLine); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }); }
From source file:com.lastsoft.plog.GamesFragment.java
public void captureBox(Game game) { theGame = game;//from w ww .j a va 2s . com try { InputMethodManager inputManager = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception ignored) { } Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(mActivity.getPackageManager()) != null) { // Create the File where the photo should go photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (photoFile != null) { photoUri = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(takePictureIntent, 0); } } }
From source file:pl.mrwojtek.sensrec.app.Records.java
public boolean shareActivated() { ArrayList<Uri> files = new ArrayList<>(); for (RecordEntry recordEntry : records) { if (recordEntry.isActivated()) { files.add(Uri.fromFile(recordEntry.getFile())); }// w w w . ja v a 2 s .c o m } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_SUBJECT, "Sensors Record recordings."); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { getActivity().startActivity(intent); return true; } else { return false; } }
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
public void dispatchKeyShortcutEvent(int keyCode) { switch (keyCode) { // CTRL+E: Edit case KeyEvent.KEYCODE_E: Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle);/*from www. jav a 2 s . com*/ getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); break; // CTRL+D: Delete case KeyEvent.KEYCODE_D: // Show delete dialog listener.showDeleteDialog(); break; // CTRL+H: Share case KeyEvent.KEYCODE_H: // Send a share intent Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad); shareIntent.setType("text/plain"); // Verify that the intent will resolve to an activity, and send if (shareIntent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); break; } }
From source file:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { Log.w(TAG, "Restored state"); mOriginalSettings = savedInstanceState.getBundle(ORIGINAL_SETTINGS_NAME); } else {/*from w w w .j av a2 s. co m*/ mOriginalSettings = new Bundle(); } mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName()); mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = getIntent(); String action = intent.getAction(); Log.d(TAG, "ByodHelperActivity.onCreate: " + action); // we are explicitly started by {@link DeviceAdminTestReceiver} after a successful provisioning. if (action.equals(ACTION_PROFILE_PROVISIONED)) { // Jump back to CTS verifier with result. Intent response = new Intent(ACTION_PROFILE_OWNER_STATUS); response.putExtra(EXTRA_PROVISIONED, isProfileOwner()); startActivityInPrimary(response); // Queried by CtsVerifier in the primary side using startActivityForResult. } else if (action.equals(ACTION_QUERY_PROFILE_OWNER)) { Intent response = new Intent(); response.putExtra(EXTRA_PROVISIONED, isProfileOwner()); setResult(RESULT_OK, response); // Request to delete work profile. } else if (action.equals(ACTION_REMOVE_MANAGED_PROFILE)) { if (isProfileOwner()) { Log.d(TAG, "Clearing cross profile intents"); mDevicePolicyManager.clearCrossProfileIntentFilters(mAdminReceiverComponent); mDevicePolicyManager.wipeData(0); showToast(R.string.provisioning_byod_profile_deleted); } } else if (action.equals(ACTION_INSTALL_APK)) { boolean allowNonMarket = intent.getBooleanExtra(EXTRA_ALLOW_NON_MARKET_APPS, false); boolean wasAllowed = getAllowNonMarket(); // Update permission to install non-market apps setAllowNonMarket(allowNonMarket); mOriginalSettings.putBoolean(INSTALL_NON_MARKET_APPS, wasAllowed); // Request to install a non-market application- easiest way is to reinstall ourself final Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE) .setData(Uri.parse("package:" + getPackageName())) .putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true).putExtra(Intent.EXTRA_RETURN_RESULT, true); startActivityForResult(installIntent, REQUEST_INSTALL_PACKAGE); // Not yet ready to finish- wait until the result comes back return; // Queried by CtsVerifier in the primary side using startActivityForResult. } else if (action.equals(ACTION_CHECK_INTENT_FILTERS)) { final boolean intentFiltersSetForManagedIntents = new IntentFiltersTestHelper(this) .checkCrossProfileIntentFilters(IntentFiltersTestHelper.FLAG_INTENTS_FROM_MANAGED); setResult(intentFiltersSetForManagedIntents ? RESULT_OK : RESULT_FAILED, null); } else if (action.equals(ACTION_CAPTURE_AND_CHECK_IMAGE)) { // We need the camera permission to send the image capture intent. grantCameraPermissionToSelf(); Intent captureImageIntent = getCaptureImageIntent(); Pair<File, Uri> pair = getTempUri("image.jpg"); mImageFile = pair.first; mImageUri = pair.second; captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); if (captureImageIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(captureImageIntent, REQUEST_IMAGE_CAPTURE); } else { Log.e(TAG, "Capture image intent could not be resolved in managed profile."); showToast(R.string.provisioning_byod_capture_media_error); finish(); } return; } else if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT) || action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITHOUT_EXTRA_OUTPUT)) { // We need the camera permission to send the video capture intent. grantCameraPermissionToSelf(); Intent captureVideoIntent = getCaptureVideoIntent(); int videoCaptureRequestId; if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT)) { mVideoUri = getTempUri("video.mp4").second; captureVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mVideoUri); videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITH_EXTRA_OUTPUT; } else { videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITHOUT_EXTRA_OUTPUT; } if (captureVideoIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(captureVideoIntent, videoCaptureRequestId); } else { Log.e(TAG, "Capture video intent could not be resolved in managed profile."); showToast(R.string.provisioning_byod_capture_media_error); finish(); } return; } else if (action.equals(ACTION_CAPTURE_AND_CHECK_AUDIO)) { Intent captureAudioIntent = getCaptureAudioIntent(); if (captureAudioIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(captureAudioIntent, REQUEST_AUDIO_CAPTURE); } else { Log.e(TAG, "Capture audio intent could not be resolved in managed profile."); showToast(R.string.provisioning_byod_capture_media_error); finish(); } return; } else if (ACTION_KEYGUARD_DISABLED_FEATURES.equals(action)) { final int value = intent.getIntExtra(EXTRA_PARAMETER_1, DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE); mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminReceiverComponent, value); } else if (ACTION_LOCKNOW.equals(action)) { mDevicePolicyManager.lockNow(); setResult(RESULT_OK); } else if (action.equals(ACTION_TEST_NFC_BEAM)) { Intent testNfcBeamIntent = new Intent(this, NfcTestActivity.class); testNfcBeamIntent.putExtras(intent); startActivity(testNfcBeamIntent); finish(); return; } else if (action.equals(ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG)) { sendIntentInsideChooser(new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL)); } else if (action.equals(ACTION_TEST_APP_LINKING_DIALOG)) { mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(), UserManager.ALLOW_PARENT_PROFILE_APP_LINKING); Intent toSend = new Intent(Intent.ACTION_VIEW); toSend.setData(Uri.parse("http://com.android.cts.verifier")); sendIntentInsideChooser(toSend); } else if (action.equals(ACTION_SET_USER_RESTRICTION)) { final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1); if (restriction != null) { mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(), restriction); } } else if (action.equals(ACTION_CLEAR_USER_RESTRICTION)) { final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1); if (restriction != null) { mDevicePolicyManager.clearUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(), restriction); } } else if (action.equals(ACTION_BYOD_SET_LOCATION_AND_CHECK_UPDATES)) { handleLocationAction(); return; } else if (action.equals(ACTION_NOTIFICATION)) { showNotification(Notification.VISIBILITY_PUBLIC); } else if (ACTION_NOTIFICATION_ON_LOCKSCREEN.equals(action)) { mDevicePolicyManager.lockNow(); showNotification(Notification.VISIBILITY_PRIVATE); } else if (ACTION_CLEAR_NOTIFICATION.equals(action)) { mNotificationManager.cancel(NOTIFICATION_ID); } else if (ACTION_TEST_SELECT_WORK_CHALLENGE.equals(action)) { mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, Color.BLUE); mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent, getResources().getString(R.string.provisioning_byod_confirm_work_credentials_header)); startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD)); } else if (ACTION_LAUNCH_CONFIRM_WORK_CREDENTIALS.equals(action)) { KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); Intent launchIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null); startActivity(launchIntent); } else if (ACTION_SET_ORGANIZATION_INFO.equals(action)) { if (intent.hasExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME)) { final String organizationName = intent .getStringExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME); mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent, organizationName); } final int organizationColor = intent.getIntExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_COLOR, mDevicePolicyManager.getOrganizationColor(mAdminReceiverComponent)); mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, organizationColor); } else if (ACTION_TEST_PARENT_PROFILE_PASSWORD.equals(action)) { startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD)); } // This activity has no UI and is only used to respond to CtsVerifier in the primary side. finish(); }
From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Override default Android "up" behavior to instead mimic the back button getActivity().onBackPressed();/*from ww w .j a v a 2 s . c om*/ return true; // Edit button case R.id.action_edit: Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return true; // Delete button case R.id.action_delete: listener.showDeleteDialog(); return true; // Share menu item case R.id.action_share: // Send a share intent Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, contentsOnLoad); intent.setType("text/plain"); // Verify that the intent will resolve to an activity, and send if (intent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to))); return true; // Export menu item case R.id.action_export: listener.exportNote(filename); return true; // Print menu item case R.id.action_print: listener.printNote(contentsOnLoad); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.yeldi.yeldibazaar.AppDetails.java
public void tryOpenUri(String s) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s)); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent);// www . j a v a 2s . com else Toast.makeText(this, getString(R.string.no_handler_app, intent.getDataString()), Toast.LENGTH_LONG) .show(); }