List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.hotmart.dragonfly.check.ui.ShareChecklistActivity.java
@OnClick(R.id.share) void onClickShare() { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.text_share)); intent.setType("*/*"); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent);//ww w .j ava2s .co m } }
From source file:com.thedrycake.tempincity.ui.MainActivity.java
private void onTempClick() { City city = Cities.getCityByName(getCurrentCityName(), null); URL webAddress = null;//from w w w .j a va2 s.c o m try { webAddress = city != null ? city.getUserFriendlyWebAddress() : null; } catch (MalformedURLException e) { Log.e(LOG_TAG, "Incorrect user friendly web address", e); } if (webAddress != null) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress.toExternalForm())); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }
From source file:com.example.android.sunshine.app.ui.ForecastFragment.java
private void openPreferredLocationInMap() { String location = PreferenceUtils.getInstance(getActivity()) .getStringPreference(PreferenceKey.PREF_LOCATION_KEY); Uri geoLocation = Uri.parse("geo:0,0?").buildUpon().appendQueryParameter("q", location).build(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation);// w w w . ja va 2 s .c o m if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.i(TAG, "Couldnt call " + location + "not found"); } }
From source file:com.example.admin.news.mvp.ui.activities.NewsDetailActivity.java
private boolean canBrowse(Intent intent) { return intent.resolveActivity(getPackageManager()) != null && mShareLink != null; }
From source file:com.google.android.gms.samples.vision.face.photo.PhotoViewerActivity.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { }/*w w w . java 2s. com*/ // Continue only if the File was successfully created if (photoFile != null) { photoURI = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } } }
From source file:com.google.codelabs.cosu.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Setup button which calls intent to camera app to take a picture takePicButton = (Button) findViewById(R.id.pic_button); takePicButton.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .ja v a 2 s . c o m*/ public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File photoFile = null; try { photoFile = createImageFile(); } catch (IOException e) { Log.e(FILE_TAG, e.getMessage()); } if (photoFile != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } } else { Toast.makeText(getApplicationContext(), R.string.no_camera_apps, Toast.LENGTH_SHORT).show(); } } }); // Retrieve Device Policy Manager so that we can check whether we can // lock to screen later mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); lockTaskButton = (Button) findViewById(R.id.start_lock_button); lockTaskButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mDevicePolicyManager.isLockTaskPermitted(getApplicationContext().getPackageName())) { Intent lockIntent = new Intent(getApplicationContext(), LockedActivity.class); lockIntent.putExtra(EXTRA_FILEPATH, mCurrentPhotoPath); startActivity(lockIntent); finish(); } else { Toast.makeText(getApplicationContext(), R.string.not_lock_whitelisted, Toast.LENGTH_SHORT) .show(); } } }); imageView = (ImageView) findViewById(R.id.main_imageView); // Check to see if permission to access external storage is granted, // and request if not permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }
From source file:com.oscarsalguero.sunshine.MainActivity.java
private void showPreferredLocationOnMap() { String location = PreferenceManager.getDefaultSharedPreferences(this) .getString(getString(R.string.pref_location_key), getString(R.string.pref_location_default)); Intent intent = new Intent(Intent.ACTION_VIEW); Uri geoLocation = new Uri.Builder().scheme("geo").appendQueryParameter("q", location).build(); intent.setData(geoLocation);//from w w w . ja v a2s. co m if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } }
From source file:com.example.michael.bumpy.EditDetailsActivity.java
public void imageButtonListener(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageButtonToUpdate = (ImageButton) v; if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }//from w w w. j a va2 s . c om }
From source file:com.example.puter.sunshine.app.ForecastFragment.java
private void openPreferredLocationInMap() { if (null != mForecastAdapter) { Cursor c = mForecastAdapter.getCursor(); if (null != c) { c.moveToPosition(0);/*from w ww . jav a 2 s. 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!"); } } } }
From source file:com.example.android.testing.notes.addnote.AddNoteFragment.java
@Override public void openCamera(String saveTo) { // Open the camera to take a picture. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Check if there is a camera app installed to handle our Intent if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse(saveTo)); startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE_CAPTURE); } else {/*from ww w . ja va 2 s. co m*/ Snackbar.make(mTitle, getString(R.string.cannot_connect_to_camera_message), Snackbar.LENGTH_SHORT) .show(); } }