List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.example.meetingapp.ShowDetailsFragment.java
/** * Allows the user to call a provided number. *//*ww w . jav a 2 s . c o m*/ private void callNumber() { /* If there's no phone number, don't try to call. */ if (mResult.international_phone_number == null) { return; } Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + mResult.formatted_phone_number)); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } }
From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java
private void openPDF(String uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(uri)), MEDIA_TYPE_PDF); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PackageManager packageManager = getPackageManager(); assert packageManager != null; if (intent.resolveActivity(packageManager) != null) { startActivity(intent);/* w w w . j a v a 2 s. c om*/ } else { Toast.makeText(this, R.string.no_pdf_reader, Toast.LENGTH_LONG).show(); } }
From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.battery_info, root, false); mbattery_percent = (TextView) view.findViewById(R.id.batt_percent); mbattery_volt = (TextView) view.findViewById(R.id.batt_volt); mbattery_status = (TextView) view.findViewById(R.id.batt_status); mBattIcon = (ImageView) view.findViewById(R.id.batt_icon); if (new File(BAT_VOLT_PATH).exists()) { int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH)); if (volt > 5000) volt = (int) Math.round(volt / 1000.0);// in microvolts mbattery_volt.setText(volt + " mV"); mBattIcon.setVisibility(ImageView.GONE); mbattery_volt.setVisibility(TextView.VISIBLE); mbattery_volt.setOnClickListener(new View.OnClickListener() { @Override/*from ww w. j a v a 2 s . c om*/ public void onClick(View view) { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null) startActivity(powerUsageIntent); } }); mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); return true; } }); } else { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); mBattIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(powerUsageIntent); } catch (Exception e) { } } }); } SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider); if (new File(BLX_PATH).exists()) { no_settings = false; mBlxSlider.setMax(100); mBlxVal = (TextView) view.findViewById(R.id.blx_val); mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%"); mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH))); mBlxSlider.setOnSeekBarChangeListener(this); Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob); mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false)); mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(BLX_SOB, checked); if (checked) { editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH))); } editor.commit(); } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout); mpart.setVisibility(LinearLayout.GONE); } mFastChargePath = Helpers.fastcharge_path(); if (mFastChargePath != null) { no_settings = false; mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob); mFastchargeOnBoot.setChecked( mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1"))); mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply(); final NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (checked) { new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath); Notification n = new Notification.Builder(context) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.fast_charge_notification_title)) .setTicker(context.getText(R.string.fast_charge_notification_title)) .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis()) .getNotification(); //n.flags = Notification.FLAG_NO_CLEAR; nm.notify(1337, n); } else { new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath); nm.cancel(1337); } } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout); mpart.setVisibility(LinearLayout.GONE); } if (no_settings) { LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings); ns.setVisibility(LinearLayout.VISIBLE); } return view; }
From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java
/** * Add a new Intent with the resolved chain of parents for the target * activity to the task stack.//w ww .j a va2s .co m * * <p> * This is equivalent to calling {@link #addParentStack(ComponentName) * addParentStack} with the resolved ComponentName of nextIntent (if it can * be resolved), followed by {@link #addNextIntent(Intent) addNextIntent} * with nextIntent. * </p> * * @param nextIntent * Intent for the topmost Activity in the synthesized task stack. * Its chain of parents as specified in the manifest will be * added. * @return This DualTaskStackBuilder for method chaining. */ public DualTaskStackBuilder addNextIntentWithParentStack(Intent nextIntent) { ComponentName target = nextIntent.getComponent(); if (target == null) { target = nextIntent.resolveActivity(mSourceContext.getPackageManager()); } if (target != null) { addParentStack(target); } addNextIntent(nextIntent); return this; }
From source file:it.rignanese.leo.slimtwitter.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setup the sharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.activity_main); //setup the floating button FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override//from w w w .ja v a2 s . co m public void onClick(View view) { webViewTwitter.scrollTo(0, 0);//scroll up } }); // setup the refresh layout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeRefreshLayout.setColorSchemeResources(R.color.officialAzureTwitter, R.color.darkAzureSlimTwitterTheme);// set the colors swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshPage();//reload the page swipeRefresh = true; } }); // setup the webView webViewTwitter = (WebView) findViewById(R.id.webView); setUpWebViewDefaults(webViewTwitter);//set the settings goHome();//load homepage //WebViewClient that is the client callback. webViewTwitter.setWebViewClient(new WebViewClient() {//advanced set up // when there isn't a connetion public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { String summary = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><h1 " + "style='text-align:center; padding-top:15%;'>" + getString(R.string.titleNoConnection) + "</h1> <h3 style='text-align:center; padding-top:1%; font-style: italic;'>" + getString(R.string.descriptionNoConnection) + "</h3> <h5 style='text-align:center; padding-top:80%; opacity: 0.3;'>" + getString(R.string.awards) + "</h5></body></html>"; webViewTwitter.loadData(summary, "text/html; charset=utf-8", "utf-8");//load a custom html page noConnectionError = true; swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing } // when I click in a external link public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url == null || url.contains("twitter.com")) { //url is ok return false; } else { //if the link doesn't contain 'twitter.com', open it using the browser startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } //START management of loading @Override public void onPageFinished(WebView view, String url) { swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing super.onPageFinished(view, url); } //END management of loading }); //WebChromeClient for handling all chrome functions. webViewTwitter.setWebChromeClient(new WebChromeClient() { //to upload files //thanks to gauntface //https://github.com/GoogleChrome/chromium-webview-samples public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getBaseContext().getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); }
From source file:com.example.android.navigationdrawerexample.SecondActivity.java
@Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.overflow_search: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent);/* w ww .jav a 2 s . co m*/ } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } break; default: break; } return false; }
From source file:mx.com.adolfogarcia.popularmovies.view.fragment.MovieDetailFragment.java
/** * Returns an {@link Intent} that can be used to share the first movie * trailer or {@code null} if there are no trailers (or there is no app on * the device that may be used to share). * * @return an {@link Intent} that can be used to share the first movie * trailer or {@code null} if one is not available. *///from w w w.j a va2s.c om private Intent getShareFirstTrailerIntent() { if (mViewModel == null || mViewModel.getTrailers().isEmpty()) { return null; } Trailer firstTrailer = mViewModel.getTrailers().get(0); Context context = getActivity(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, firstTrailer.getVideoUri().toString()); intent.setType(PLAIN_TEXT_MEDIA_TYPE); if (intent.resolveActivity(context.getPackageManager()) == null) { Log.w(LOG_TAG, "Unable to create share intent. No application available to share."); intent = null; } return intent; }
From source file:com.example.android.phonecallingsample.MainActivity.java
/** * Uses an implicit intent to make the phone call. * Before calling, checks to see if permission is granted. * * @param view View (phone_icon) that was clicked. *//*from w ww.j a v a 2s. c o m*/ public void callNumber(View view) { EditText editText = (EditText) findViewById(R.id.editText_main); // Use format with "tel:" and phone number to create phoneNumber. String phoneNumber = String.format("tel: %s", editText.getText().toString()); // Log the concatenated phone number for dialing. Log.d(TAG, getString(R.string.dial_number) + phoneNumber); Toast.makeText(this, getString(R.string.dial_number) + phoneNumber, Toast.LENGTH_LONG).show(); // Create the intent. Intent callIntent = new Intent(Intent.ACTION_CALL); // Set the data for the intent as the phone number. callIntent.setData(Uri.parse(phoneNumber)); // If package resolves to an app, check for phone permission, // and send intent. if (callIntent.resolveActivity(getPackageManager()) != null) { checkForPhonePermission(); startActivity(callIntent); } else { Log.e(TAG, "Can't resolve app for ACTION_CALL Intent."); } }
From source file:com.alboteanu.android.sunshine.app.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);//from w w w . j a v a2 s. com 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.microsoft.assetmanagement.DisplayCarActivity.java
/** * Dispatch take picture intent.//ww w . j av a2 s. co m */ 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(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { Log.e("Asset", ex.getMessage()); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, CAMARA_REQUEST_CODE); } } }