List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java
/** * {@inheritDoc}//from w ww. j a va 2 s . com */ @Override public void openExternalSite(String url) { Logger.d(LOG_TAG, "openExternalSite() -- url: " + url); // This link is not for a page on my site, launch another Activity // that handles this URL Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } }
From source file:me.barrasso.android.volume.activities.ConfigurationActivity.java
private void launchGooglePlus() { Intent google = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.google_plus_url))); if (google.resolveActivity(getPackageManager()) != null) { startActivity(google);/*from w w w . ja va2 s .com*/ } else { Crouton.showText(this, R.string.url_error, Style.ALERT); } }
From source file:com.notepadlite.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 . j av a 2s . c o m 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: // Set current note contents to a String String contents = noteContents.getText().toString(); // Send a share intent Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, contents); 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:pwr.itapps.meetme.activity.WallActivity.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. Intent intent; if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*from ww w.j a v a 2 s . c o m*/ // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet 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; case R.id.services_download: Fragment f = getActiveFragment(); if (f instanceof FriendsFragment) { ((FriendsFragment) f).downloadContacs(); } else if (f instanceof EventListFragment) { ((EventListFragment) f).runRefresh(); } return true; case R.id.action_createEvent: // create intent to perform web search for this planet intent = new Intent(getApplicationContext(), CreateEventActivity.class); // 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:fr.bde_eseo.eseomega.lydia.LydiaActivity.java
/** * Make an Intent to Lydia App / Web navigator if app is not found *///ww w . jav a 2 s . c om void intentToLydia() { // Configure and make Lydia Intent //String intentUri; boolean closeAfter = false; // Package Lydia exists ? //intentUri = LYDIA_INTENT; // suppose yes /*if (Utilities.isPackageExisted(context, LYDIA_PACKAGE)) { intentUri = LYDIA_INTENT; } else { intentUri = MOBILE_URL; // Package doesn't exists : open URL closeAfter = true; // @see comment below Toast.makeText(context, "Le navigateur va tre ouvert.", Toast.LENGTH_SHORT).show(); }*/ Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(LYDIA_INTENT)); PackageManager packageManager = context.getPackageManager(); if (i.resolveActivity(packageManager) != null) { startActivity(i); } else { // Package doesn't exists : open URL Intent iweb = new Intent(); closeAfter = true; // @see comment below Toast.makeText(context, "Le navigateur va tre ouvert.", Toast.LENGTH_SHORT).show(); iweb.setData(Uri.parse(MOBILE_URL)); startActivity(iweb); } if (closeAfter) { new Handler().postDelayed(new Runnable() { @Override public void run() { md.dismiss(); close(); // prevent app-resume with null orderID Toast.makeText(context, "Closing LydiaActivity ...", Toast.LENGTH_SHORT).show(); } }, 1000); } }
From source file:edu.sfsu.csc780.chathub.ui.activities.MainActivity.java
private void dispatchTakePhotoIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure the implicit intent can be handled if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); }//from w w w . j a va 2 s . c o m }
From source file:com.coderdojo.libretalk.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; }//from ww w .ja va 2s. c om // Handle action buttons switch (item.getItemId()) { case R.id.action_addfriend: Fragment fragment = new AddFriendFragment(); Bundle args = new Bundle(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); return true; case R.id.action_websearch: // create intent to perform web search for this planet 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.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * take picture//from www.j a v a 2s. co 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.getContext().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getContext()); // 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:org.catnut.ui.ComposeTweetActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (!mSlidingPaneLayout.isOpen()) { mSlidingPaneLayout.openPane();// ww w. j a va2s . c o m } switch (item.getItemId()) { case R.id.pref: startActivity(SingleFragmentActivity.getIntent(this, SingleFragmentActivity.PREF)); break; case R.id.action_gallery: // todo: ????Orz if (mUris != null && mUris.size() > 0) { Toast.makeText(this, getString(R.string.only_one_pic_hint), Toast.LENGTH_LONG).show(); } else { startActivityForResult(new Intent(Intent.ACTION_PICK).setType("image/*"), 1); } break; case R.id.action_shorten: shorten(); break; case R.id.action_camera: // same as above if (mUris != null && mUris.size() > 0) { break; } Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { mTmpUri = CatnutUtils.createImageFile(); if (mTmpUri != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, mTmpUri); } startActivityForResult(intent, CAMERA); } else { Toast.makeText(this, getString(R.string.device_not_support), Toast.LENGTH_SHORT).show(); } break; case R.id.action_discovery: int cursor = mText.getSelectionStart(); mText.getText().append("##"); mText.setSelection(cursor + 1); mText.requestFocus(); break; default: break; } return super.onOptionsItemSelected(item); }
From source file:com.beesham.popularmovies.DetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_details_view, container, false); ButterKnife.bind(this, rootView); mTrailerList = new ArrayList(); mReviewsList = new ArrayList(); mReviewAdapter = new ReviewAdapter(getActivity(), mReviewsList); reviewsListView.setAdapter(mReviewAdapter); reviewsListView.setEmptyView(emptyReviewsTextView); mTrailersAdapter = new TrailersAdapter(getActivity(), mTrailerList); trailersListView.setAdapter(mTrailersAdapter); trailersListView.setEmptyView(emptyTrailersTextView); trailersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w .j a v a 2 s . c o m*/ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); String movieBaseYoutubeUrl = getString(R.string.movies_base_youtube_url, ((Trailer) mTrailerList.get(i)).getTrailerKey()); intent.setData(Uri.parse(movieBaseYoutubeUrl)); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } } }); favoriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (checkForFavorite()) { removeFavorite(); favoriteButton.setText(R.string.mark_favorite); } else { insertFavoriteMovie(); favoriteButton.setText(R.string.mark_unfavorite); } } }); Bundle args = getArguments(); if (args != null) { mUri = args.getParcelable(DetailsFragment.DETAIL_URI); } if (savedInstanceState != null && args.containsKey(DetailsFragment.DETAIL_URI)) { mUri = args.getParcelable(DetailsFragment.DETAIL_URI); } return rootView; }