List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:io.github.hidroh.materialistic.WebFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (mIsHackerNewsUrl) { return createLocalView(container, savedInstanceState); }/* w w w . j ava 2 s .c om*/ final View view = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_web, container, false); mScrollView = (NestedScrollView) view.findViewById(R.id.nested_scroll_view); final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress); mWebView = (WebView) view.findViewById(R.id.web_view); mWebView.setBackgroundColor(Color.TRANSPARENT); mWebView.setWebViewClient(new WebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(newProgress); if (newProgress == 100) { progressBar.setVisibility(View.GONE); mWebView.setBackgroundColor(Color.WHITE); mWebView.setVisibility(mExternalRequired ? View.GONE : View.VISIBLE); } } }); mWebView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { if (getActivity() == null) { return; } final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (intent.resolveActivity(getActivity().getPackageManager()) == null) { return; } mExternalRequired = true; mWebView.setVisibility(View.GONE); view.findViewById(R.id.empty).setVisibility(View.VISIBLE); view.findViewById(R.id.download_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(intent); } }); } }); mWebView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { if (mWebView.canGoBack()) { mWebView.goBack(); return true; } } return false; } }); setWebViewSettings(mWebView.getSettings()); return view; }
From source file:com.gaba.alex.trafficincidents.Adapter.IncidentsAdapter.java
@Override public void bindView(View view, final Context context, Cursor cursor) { super.bindView(view, context, cursor); final int type = cursor.getInt(cursor.getColumnIndexOrThrow(IncidentsColumns.TYPE)); final int severity = cursor.getInt(cursor.getColumnIndexOrThrow(IncidentsColumns.SEVERITY)); final double lat = cursor.getDouble(cursor.getColumnIndexOrThrow(IncidentsColumns.LAT)); final double lng = cursor.getDouble(cursor.getColumnIndexOrThrow(IncidentsColumns.LNG)); final double toLat = cursor.getDouble(cursor.getColumnIndexOrThrow(IncidentsColumns.TO_LAT)); final double toLng = cursor.getDouble(cursor.getColumnIndexOrThrow(IncidentsColumns.TO_LNG)); final long dateInMillis = Long .parseLong(cursor.getString(cursor.getColumnIndexOrThrow(IncidentsColumns.END_DATE))); final boolean roadClosed = Boolean .valueOf(cursor.getString(cursor.getColumnIndexOrThrow(IncidentsColumns.ROAD_CLOSED))); final String description = cursor.getString(cursor.getColumnIndexOrThrow(IncidentsColumns.DESCRIPTION)); TextView typeTextView = (TextView) view.findViewById(R.id.incident_type); if (typeTextView != null) { typeTextView.setText(Utility.getIncidentType(mContext, type)); }/*from w ww . ja va 2s .c o m*/ TextView severityTextView = (TextView) view.findViewById(R.id.incident_severity); if (severityTextView != null) { severityTextView.setText(Utility.getIncidentSeverity(mContext, severity)); severityTextView.setTextColor(ContextCompat.getColor(mContext, Utility.getIncidentColor(severity))); } TextView roadClosedTextView = (TextView) view.findViewById(R.id.incident_road_closed); if (roadClosedTextView != null) { roadClosedTextView.setText(String.format("%s: ", mContext.getString(R.string.road_closed))); } TextView roadClosedContentTextView = (TextView) view.findViewById(R.id.incident_road_closed_content); if (roadClosedContentTextView != null) { roadClosedContentTextView .setText(roadClosed ? mContext.getString(R.string.yes) : mContext.getString(R.string.no)); roadClosedContentTextView.setTextColor(ContextCompat.getColor(mContext, roadClosed ? android.R.color.holo_red_light : android.R.color.holo_green_dark)); } TextView dateTextView = (TextView) view.findViewById(R.id.incident_end_date); if (dateTextView != null) { dateTextView.setText(String.format("%s: ", mContext.getString(R.string.estimated_end_date))); } TextView dateContentTextView = (TextView) view.findViewById(R.id.incident_end_date_content); if (dateContentTextView != null) { dateContentTextView.setText(DateFormat.getDateInstance().format(new Date(dateInMillis))); } TextView descriptionTextView = (TextView) view.findViewById(R.id.incident_description); if (descriptionTextView != null) { descriptionTextView.setText(String.format("%s: ", mContext.getString(R.string.local_description))); } TextView descriptionContentTextView = (TextView) view.findViewById(R.id.incident_description_content); if (descriptionContentTextView != null) { descriptionContentTextView.setText(description); } ImageView showOnMapImageView = (ImageView) view.findViewById(R.id.show_on_map_button); showOnMapImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = Utility.buildShowOnMapIntent(mContext, lat, lng, toLat, toLng, severity, description); if (intent.resolveActivity(mContext.getPackageManager()) != null) { mContext.startActivity(intent); } } }); ImageView shareImageView = (ImageView) view.findViewById(R.id.share_button); shareImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); String shareText = Utility.getIncidentType(mContext, type) + "\n\n" + mContext.getString(R.string.local_description) + ": " + description + "\n\n" + mContext.getString(R.string.severity) + ": " + Utility.getIncidentSeverity(mContext, severity) + "\n\n" + mContext.getString(R.string.road_closed) + ": " + (roadClosed ? mContext.getString(R.string.yes) : mContext.getString(R.string.no)) + "\n\n" + mContext.getString(R.string.provided_by) + ": " + mContext.getString(R.string.app_name); intent.putExtra(Intent.EXTRA_TEXT, shareText); if (intent.resolveActivity(mContext.getPackageManager()) != null) { mContext.startActivity(intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } } }); }
From source file:com.demo.weather.sunshine.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 (c != null) { c.moveToPosition(0);//from w w w . 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.royclarkson.springagram.PhotoAddFragment.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null;/*from ww w . ja v a 2s . c om*/ try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } // 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:com.darizotas.metadatastrip.FileDetailFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.location: Uri geoLocation = getUriGeoLocation(); if (geoLocation != null) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent);// ww w .ja v a 2s. c o m } } break; case R.id.about: AboutDialogFragment aboutDialog = new AboutDialogFragment(); aboutDialog.show(getFragmentManager(), "fragment_about_dialog"); break; } return super.onOptionsItemSelected(item); }
From source file:com.example.android.spotifystreamer.app.spotifystreamerFragment.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 != mspotifystreamerAdapter) { Cursor c = mspotifystreamerAdapter.getCursor(); if (null != c) { c.moveToPosition(0);//from w w w . j av 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!"); } } } }
From source file:com.my.seams_carv.StartActivity.java
private void dispatchTakePhotoIntent() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { File file = null;//from w ww .j av a 2 s . c o m try { file = createImageFile(); } catch (IOException ex) { // DO NOTHING. Log.d("xyz", ex.getMessage()); } // Continue only if the File was successfully created. if (file != null) { // Save the path. mPhotoPath = Uri.fromFile(file); Log.d("xyz", String.format("Saved file=%s", file.getAbsolutePath())); // Specify the authorities under which this content provider can // be found. Multiple authorities may be supplied by separating // them with a semicolon. Authority names should use a Java-style // naming convention (such as com.google.provider.MyProvider) in // order to avoid conflicts. Typically this name is the same as // the class implementation describing the provider's data // structure. final String authority = getResources().getString(R.string.file_provider_authority); final Uri uri = FileProvider.getUriForFile(this, authority, file); Log.d("xyz", String.format("Generated uri=%s", uri)); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, REQ_TAKE_PHOTO); } } }
From source file:info.martinmarinov.dvbdriver.ExceptionDialog.java
private void sendEmail(String[] addresses, String subject, String message) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_EMAIL, addresses); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent);/*from w w w.j ava 2 s. co m*/ } else { Toast.makeText(getContext(), R.string.cannot_send_email, Toast.LENGTH_LONG).show(); } }
From source file:ph.devcon.android.profile.EditUserProfileActivity.java
public void onClickUserProfile(View view) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { EventBus.getDefault().postSticky(new LaunchCameraEvent(profile)); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }//from w w w .j av a 2s . c om }
From source file:com.pddstudio.share.Share.java
/** * Immediately share the {@linkplain Intent} configured by this {@link Share} instance. * @param chooserIntent - Whether the {@linkplain Intent} should be configured with or without a chooser. */// w w w . ja v a2s. c om public void share(boolean chooserIntent) { if (chooserIntent) { Intent intent = intentBuilder.createChooserIntent(); checkForAttachements(intent); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } else { Log.e("Share", "Unable to start activity. There's no activity that can handle this type of request!"); } } else { Intent intent = intentBuilder.getIntent(); checkForAttachements(intent); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } else { Log.e("Share", "Unable to start activity. There's no activity that can handle this type of request!"); } } }