List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.univpm.s1055802.faceplusplustester.Detect.AcquirePhoto.java
/** * Richiama la fotocamera, acquisisce la foto e la salva in un file * @return il file salvato/* ww w.j a va 2s .com*/ */ private void Acquire() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent photoFile = null; if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File Log.v("alert", "file error"); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:sg.fxl.topeka.widget.quiz.ImageQuizView.java
@Override protected View createQuizContentView() { ViewGroup view = (ViewGroup) getLayoutInflater().inflate(R.layout.quiz_button_image, this, false); button = (Button) view.findViewById(R.id.button); imageView = (ImageView) view.findViewById(R.id.imageView); imageView.setVisibility(GONE);//from w ww . j a v a 2s. co m button.setText("Take Picture"); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) { // Create the File where the photo should go photoFile = null; try { photoFile = createImageFile(); } catch (IOException e) { // Error occurred while creating the File Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); Log.e("ImageQuizView", e.getMessage(), e); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); // Register for on activity result QuizActivity activity = ((QuizActivity) getContext()); activity.registerOnActivityResult(ImageQuizView.this); activity.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } } }); return view; }
From source file:com.example.calero.counters.app.UI.Fragments.DetailFragment.java
private void openMapView() { if (latitudeValue != 0 || latitudeValue != 0) { Uri uri = Uri.parse("geo:" + getStringLatitudeValue() + "," + getStringLongitudeValue()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri);//from w ww . ja v a 2 s. c o m if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.d(LOG_TAG, "Couldn't call " + uri.toString() + ", no receiving apps installed!"); } } else { Log.d(LOG_TAG, "URI " + uri); Log.d(LOG_TAG, "Latitude " + latitudeTextView.getText().toString()); Log.d(LOG_TAG, "Longitude " + longitudeTextView.getText().toString()); } }
From source file:arun.com.chameleonskinforkwlp.activities.CameraCapturerActivity.java
private void launchCamera() { final Intent capturePicIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Check if any app can handle this intent for us. final ComponentName componentName = capturePicIntent.resolveActivity(getPackageManager()); if (componentName != null) { File imageFile = null;// ww w .j a v a 2 s .c o m try { imageFile = createTemporaryFile(); } catch (IOException ex) { Timber.e("Error while creating image file", ex); } if (imageFile != null) { final Uri photoURI = FileProvider.getUriForFile(this, "arun.com.chameleonskinforkwlp.fileprovider", imageFile); capturePicIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(capturePicIntent, REQUEST_IMAGE_CAPTURE); } else { onCameraLaunchingFailed(); } } else { onNoCameraDetected(); } }
From source file:com.example.android.mmschallenge.MainActivity.java
/** * Sets the image Uri and creates implicit intent with ACTION_SEND * to launch an app to send the image./*from www. j ava2s. c om*/ */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if (requestCode == IMAGE_PICK) { if (resultCode == RESULT_OK) { Log.d(TAG, getString(R.string.picture_chosen)); Uri mSelectedImage = imageReturnedIntent.getData(); Log.d(TAG, "onActivityResult: " + mSelectedImage.toString()); Intent smsIntent = new Intent(Intent.ACTION_SEND); smsIntent.putExtra(Intent.EXTRA_STREAM, mSelectedImage); smsIntent.setType("image/*"); if (smsIntent.resolveActivity(getPackageManager()) != null) { startActivity(smsIntent); } else { Log.d(TAG, "Can't resolve app for ACTION_SEND Intent."); } } } }
From source file:com.popofibo.weatherpop.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (drawToggle.onOptionsItemSelected(item)) { return true; }//from ww w .j av a 2s. c om switch (item.getItemId()) { case R.id.action_websearch: Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getActionBar().getTitle()); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; case R.id.action_refresh: intent = new Intent(this, WeatherPopDisplayActivity.class); intent.putExtra(WeatherPopConstants.EXTRA_MESSAGE, message); intent.putExtra(WeatherPopConstants.EXTRA_OPTION, option); startActivity(intent); default: return super.onOptionsItemSelected(item); } }
From source file:com.italankin.dictionary.ui.translation.TranslationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_share: String text = mData.means + "\n" + mData.synonyms + "\n" + mData.examples; Intent intent = ShareCompat.IntentBuilder.from(this).setType("text/plain").setText(text) .setSubject(mData.text).getIntent(); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent);//from w w w . j a va 2s. c o m } else { Toast.makeText(this, R.string.error_no_app, Toast.LENGTH_SHORT).show(); } return true; } return super.onOptionsItemSelected(item); }
From source file:com.pickr.activities.PhotosPagerActivity.java
@Override public boolean handleMessage(Message msg) { switch (msg.what) { case SavePhotoTask.PHOTO_SAVED: Toast.makeText(this, R.string.photo_saved, Toast.LENGTH_LONG).show(); return true; case SavePhotoTask.PHOTO_SAVE_ERROR: ErrorDisplayer.displayToast(msg, this); return true; case PhotoInfosLoader.PHOTO_INFOS_LOADED: PhotoInformations infos = (PhotoInformations) msg.obj; PhotoInfosDialog dialog = new PhotoInfosDialog(infos, this) { @Override/* ww w . j av a2 s .c o m*/ protected void onShowLocationMap(PhotoLocation location, PhotoInfos infos) { Uri uri = Uri.parse("geo:0,0?q=" + Double.toString(location.getLatitude()) + "," + Double.toString(location.getLongitude()) + "(" + infos.getTitle() + ")"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }; dialog.show(); } return false; }
From source file:com.free.underground.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }// w w w . ja va2 s . co m // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getActionBar().getTitle()); 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:tom.udacity.sample.sunrise.ForecastFragment.java
private void openPreferredLocationInMap() { // Using the URI scheme for showing a location found on a map. This super-handy // intent can is detailed in the "Common Intents" page of Android's developer site: // http://developer.android.com/guide/components/intents-common.html#Maps if (null != mForecastAdapter) { Cursor c = mForecastAdapter.getCursor(); if (null != c) { c.moveToPosition(0);/* w ww. j a v a2s. c o m*/ String posLat = c.getString(COL_COORD_LAT); String posLong = c.getString(COL_COORD_LONG); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } } } }