List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w. j a v a2s . com*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main__activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (toolbar != null) { toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Helpers.isOnline(ShareActivity.this)) { Intent intent = new Intent(ShareActivity.this, MainActivity.class); startActivityForResult(intent, 100); overridePendingTransition(0, 0); finish(); } else { Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } }); } setTitle(R.string.new_post); progressBar = (ProgressBar) findViewById(R.id.progressBar); swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); podDomain = ((App) getApplication()).getSettings().getPodDomain(); webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); WebSettings wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, url); if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { Log.i(TAG, "Finished loading URL: " + url); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.applyDiasporaMobileSiteChanges(wv); } if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(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 Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image", Snackbar.LENGTH_LONG).show(); } // 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; } }); if (savedInstanceState == null) { if (Helpers.isOnline(ShareActivity.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { if (intent.hasExtra(Intent.EXTRA_SUBJECT)) { handleSendSubject(intent); } else { handleSendText(intent); } } else if (type.startsWith("image/")) { // TODO Handle single image being sent -> see manifest handleSendImage(intent); } //} else { // Handle other intents, such as being started from the home screen } }
From source file:com.zira.registration.DocumentUploadActivity.java
protected void selectImage() { final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this); builder.setTitle("Add Photo!"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override/* w w w . j a v a2 s .com*/ public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Take Photo")) { 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 { mCurrentPhotoPath = Util.createImageFile(); photoFile = new File(mCurrentPhotoPath); } catch (Exception ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, 1); } } } else if (options[item].equals("Choose from Gallery")) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:com.lauszus.dronedraw.DroneDrawActivity.java
private void sendEmail(File file) { Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("vnd.android.cursor.dir/email"); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "lauszus@gmail.com" }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Drone path"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Please see attachment"); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); if (emailIntent.resolveActivity(getPackageManager()) != null) { // Make sure that an app exist that can handle the intent startActivity(emailIntent);//from w w w. j a v a 2 s .co m } else Toast.makeText(getApplicationContext(), "No email app found", Toast.LENGTH_SHORT).show(); }
From source file:com.ant.sunshine.app.fragments.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 ava2s . c o m String posLat = c.getString(ForecastConstants.COL_COORD_LAT); String posLong = c.getString(ForecastConstants.COL_COORD_LONG); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getCurrentActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } } } }
From source file:hack.ddakev.roadrant.MainActivity.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }
From source file:it.rignanese.leo.slimfacebook.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setup the sharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); //setup the theme //int savedThemeId = Integer.parseInt(savedPreferences.getString("pref_key_theme8", "2131361965"));//get the last saved theme id //setTheme(savedThemeId);//this refresh the theme if necessary // TODO fix the change of status bar setContentView(R.layout.activity_main);//load the layout // setup the refresh layout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeRefreshLayout.setColorSchemeResources(R.color.officialBlueFacebook, R.color.darkBlueSlimFacebookTheme);// set the colors swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override//from w w w.j ava 2s. c o m public void onRefresh() { refreshPage();//reload the page swipeRefresh = true; } }); // setup the webView webViewFacebook = (WebView) findViewById(R.id.webView); setUpWebViewDefaults(webViewFacebook);//set the settings goHome();//load homepage //WebViewClient that is the client callback. webViewFacebook.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>"; webViewFacebook.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("facebook.com")) { //url is ok return false; } else { if (url.contains("https://scontent")) { //TODO add the possibility to download and share directly Toast.makeText(getApplicationContext(), getString(R.string.downloadOrShareWithBrowser), Toast.LENGTH_LONG).show(); //TODO get bitmap from url Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } //if the link doesn't contain 'facebook.com', open it using the browser startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } //START management of loading @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { //TODO when I push on messages, open messanger // if(url!=null){ // if (url.contains("soft=messages") || url.contains("facebook.com/messages")) { // Toast.makeText(getApplicationContext(),"Open Messanger", // Toast.LENGTH_SHORT).show(); // startActivity(new Intent(getPackageManager().getLaunchIntentForPackage("com.facebook.orca")));//messanger // } // } // show you progress image if (!swipeRefresh) { final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh); refreshItem.setActionView(R.layout.circular_progress_bar); } swipeRefresh = false; super.onPageStarted(view, url, favicon); } @Override public void onPageFinished(WebView view, String url) { // hide your progress image final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh); refreshItem.setActionView(null); super.onPageFinished(view, url); swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing } //END management of loading }); //WebChromeClient for handling all chrome functions. webViewFacebook.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:es.uja.photofirma.android.CameraActivity.java
/** * Se ejecuta al pulsar sobre el boton para abrir la captura de fotos, inicia la captura y almacena la fotografa realizada *//*from ww w . ja va 2s . com*/ public void onTakeAPhoto(View view) { logger.appendLog(300, "el usuario abre la aplicacion de fotos"); //Se crea nueva instancia de la clase PhotoMaker() para automatizar el proceso de trabajo con fotografas PhotoCapture = new PhotoMaker(); File imagen = PhotoCapture.savePhoto(); photoLocation = imagen.getAbsolutePath(); //Se redirige al usuario a la app de captura de fotografas Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(imagen)); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Toast.makeText(getApplicationContext(), getString(R.string.privacy_alert), Toast.LENGTH_LONG).show(); startActivityForResult(takePictureIntent, CameraActivity.REQUEST_IMAGE_CAPTURE); } }
From source file:com.g11x.checklistapp.ChecklistItemActivity.java
private void createUI() { TextView name = (TextView) findViewById(R.id.name); name.setText(checklistItem.getName(language)); TextView description = (TextView) findViewById(R.id.description); description.setText(checklistItem.getDescription(language)); Button getDirections = (Button) findViewById(R.id.directions); getDirections.setOnClickListener(new View.OnClickListener() { @Override/*from w w w.j ava 2 s.c om*/ public void onClick(View view) { ChecklistItemActivity.this.onClickGetDirections(); } }); Button doneness = (Button) findViewById(R.id.doneness); if (checklistItem.isDone()) { doneness.setTextColor(ContextCompat.getColor(ChecklistItemActivity.this, R.color.primary)); doneness.setPaintFlags(doneness.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); doneness.setText(getResources().getString(R.string.complete)); doneness.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check_box_accent_24dp, 0, 0, 0); } else { doneness.setTextColor(Color.BLACK); doneness.setPaintFlags(doneness.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG)); doneness.setText(getResources().getString(R.string.mark_as_done)); doneness.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check_box_outline_blank_black_24dp, 0, 0, 0); } doneness.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ChecklistItemActivity.this.onClickIsDone(); } }); Button sendEmail = (Button) findViewById(R.id.send_email); if (checklistItem.getEmail() != null && !checklistItem.getEmail().equals("")) { sendEmail.setVisibility(View.VISIBLE); sendEmail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); intent.putExtra(Intent.EXTRA_EMAIL, checklistItem.getEmail()); intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.sent_from_rst_checklist_app)); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(Intent.createChooser(intent, "Send e-mail")); } } }); } else { sendEmail.setVisibility(View.GONE); } Button call = (Button) findViewById(R.id.call); if (checklistItem.getPhone() != null && !checklistItem.getPhone().equals("")) { call.setVisibility(View.VISIBLE); call.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + checklistItem.getPhone())); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }); } else { call.setVisibility(View.GONE); } }
From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.FileExplorerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); AlfrescoAccount acc = SessionUtils.getAccount(getActivity()); Bundle b = getArguments();/*from w ww . ja v a2 s . c o m*/ if (b == null) { if (acc != null) { parent = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(acc); if (parent == null) { AlfrescoNotificationManager.getInstance(getActivity()) .showLongToast(getString(R.string.sdinaccessible)); return; } } else { AlfrescoNotificationManager.getInstance(getActivity()) .showLongToast(getString(R.string.loginfirst)); return; } } if (AlfrescoStorageManager.getInstance(getActivity()) != null && AlfrescoStorageManager.getInstance(getActivity()).getRootPrivateFolder() != null) { privateFolder = AlfrescoStorageManager.getInstance(getActivity()).getRootPrivateFolder() .getParentFile(); } displayTitle(); // Test Audio Recording Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); hasAudioRecorder = intent.resolveActivity(getActivity().getPackageManager()) != null; }
From source file:com.owncloud.android.ui.helpers.FilesUploadHelper.java
/** * Function to send an intent to the device's camera to capture a picture * */// ww w . j ava 2 s .c o m public void uploadFromCamera(final int requestCode) { Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photoFile = createImageFile(); if (photoFile != null) { Uri photoUri = FileProvider.getUriForFile(activity.getApplicationContext(), activity.getResources().getString(R.string.file_provider_authority), photoFile); pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); } if (pictureIntent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivityForResult(pictureIntent, requestCode); } }