List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:com.architjn.materialicons.ui.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_sendemail) { StringBuilder emailBuilder = new StringBuilder(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:" + getResources().getString(R.string.email_id))); intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject)); emailBuilder.append("\n \n \nOS Version: ").append(System.getProperty("os.version")).append("(") .append(Build.VERSION.INCREMENTAL).append(")"); emailBuilder.append("\nOS API Level: ").append(Build.VERSION.SDK_INT); emailBuilder.append("\nDevice: ").append(Build.DEVICE); emailBuilder.append("\nManufacturer: ").append(Build.MANUFACTURER); emailBuilder.append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT) .append(")"); PackageInfo appInfo = null;/*from w w w.ja v a 2s . c o m*/ try { appInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } assert appInfo != null; emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName); emailBuilder.append("\nApp Version Code: ").append(appInfo.versionCode); intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()); startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title)))); return true; } else if (id == R.id.action_share) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); String shareBody = getResources().getString(R.string.share_one) + getResources().getString(R.string.developer_name) + getResources().getString(R.string.share_two) + MARKET_URL + getPackageName(); sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title)))); } else if (id == R.id.action_changelog) { showChangelog(); } return super.onOptionsItemSelected(item); }
From source file:de.stadtrallye.rallyesoft.model.pictures.PictureManager.java
/** * Get an intent to either take a picture with the camera app or select an app that can pick an existing picture *//*w ww . j a v a 2s . co m*/ public Intent startPictureTakeOrSelect(SourceHint sourceHint) { //Attention: Our RequestCode will not be used for the result, if a jpeg is picked, data.getType will contain image/jpeg, if the picture was just taken with the camera it will be null Intent pickIntent = new Intent(); pickIntent.setType("image/jpeg"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { pickIntent.setAction(Intent.ACTION_OPEN_DOCUMENT); pickIntent.addCategory(Intent.CATEGORY_OPENABLE); } else { pickIntent.setAction(Intent.ACTION_GET_CONTENT); } Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri fileUri = getPicturePlaceholderUri(PictureManager.MEDIA_TYPE_IMAGE, sourceHint); // reserve a filename to save the image takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name takePhotoIntent.putExtra("return-data", true); Intent chooserIntent = Intent.createChooser(pickIntent, context.getString(R.string.select_take_picture)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent }); return chooserIntent; }
From source file:app.axe.imooc.zxing.app.CaptureActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == MY_PERMISSIONS_REQUEST_CAMERA) { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { //?//from w w w .j av a 2s . c o m } else { initCamera(surfaceHolder); } } else if (requestCode == MY_PERMISSIONS_REQUEST_XIANGCE) { if (ContextCompat.checkSelfPermission(CaptureActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { } else { // Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT" innerIntent.setType("image/*"); Intent wrapperIntent = Intent.createChooser(innerIntent, "?"); startActivityForResult(wrapperIntent, REQUEST_CODE); } } }
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/*ww w . j av a 2 s . c o m*/ 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.example.ivonneortega.the_news_project.detailView.CollectionDemoActivity.java
/** * Method that launches the share intent *///ww w .j a v a 2 s . c om public void share() { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, mArticle.getUrl()); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, "Share this mArticle using..")); }
From source file:com.anysoftkeyboard.ui.dev.DeveloperToolsFragment.java
private void shareFile(File fileToShare, String title, String message) { Intent sendMail = new Intent(); sendMail.setAction(Intent.ACTION_SEND); sendMail.setType("plain/text"); sendMail.putExtra(Intent.EXTRA_SUBJECT, title); sendMail.putExtra(Intent.EXTRA_TEXT, message); if (fileToShare != null) { sendMail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare)); }/*from ww w . jav a2 s .c o m*/ try { Intent sender = Intent.createChooser(sendMail, "Share"); sender.putExtra(Intent.EXTRA_SUBJECT, title); sender.putExtra(Intent.EXTRA_TEXT, message); startActivity(sender); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity().getApplicationContext(), "Unable to send bug report via e-mail!", Toast.LENGTH_LONG).show(); } }
From source file:com.code.android.vibevault.ShowDetailsScreen.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.nowPlaying: //Open playlist activity Intent i = new Intent(ShowDetailsScreen.this, NowPlayingScreen.class); startActivity(i);//ww w . j a va 2 s .c o m break; case R.id.recentShows: Intent rs = new Intent(ShowDetailsScreen.this, RecentShowsScreen.class); startActivity(rs); break; case R.id.scrollableDialog: AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Help!"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null); ((TextView) v.findViewById(R.id.DialogText)).setText(R.string.show_details_screen_help); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { } }); ad.setView(v); ad.show(); break; case R.id.emailLink: final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Great show on archive.org: " + show.getArtistAndTitle()); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey,\n\nYou should listen to " + show.getArtistAndTitle() + ". You can find it here: " + show.getShowURL() + "\n\nSent using VibeVault for Android."); startActivity(Intent.createChooser(emailIntent, "Send mail...")); break; case R.id.downloadShow: for (int j = 0; j < downloadLinks.size(); j++) { downloadLinks.get(j).setDownloadShow(show); dService.addSong(downloadLinks.get(j)); } break; default: break; } return true; }
From source file:com.code19.library.SystemUtils.java
public static void shareText(Context ctx, String title, String text) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, text); ctx.startActivity(Intent.createChooser(intent, title)); /* List<ResolveInfo> ris = getShareTargets(ctx); if (ris != null && ris.size() > 0) { ctx.startActivity(Intent.createChooser(intent, title)); }*//* w w w. j a v a 2 s . c o m*/ }
From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java
private void createInstagramIntent(String type, String mediaPath, String caption) { // Create the new Intent using the 'Send' action. Intent share = new Intent(Intent.ACTION_SEND); // Set the MIME type share.setType(type);/*from w ww. ja va 2 s .c o m*/ // Create the URI from the media File media = new File(mediaPath); Uri uri = Uri.fromFile(media); // Add the URI and the caption to the Intent. share.putExtra(Intent.EXTRA_STREAM, uri); share.putExtra(Intent.EXTRA_TEXT, caption); // Broadcast the Intent. startActivity(Intent.createChooser(share, "Share to")); }
From source file:key.secretkey.crypto.PgpHandler.java
public void shareAsPlaintext() { if (findViewById(R.id.share_password_as_plaintext) == null) return;//from w w w . ja v a 2 s. c o m Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword); sendIntent.setType("text/plain"); startActivity( Intent.createChooser(sendIntent, getResources().getText(R.string.send_plaintext_password_to)));//Always show a picker to give the user a chance to cancel }