List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE
String ACTION_IMAGE_CAPTURE
To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.
Click Source Link
From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java
public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) { ArrayList<String> options = new ArrayList<String>(); final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); PackageManager pm = fragment.getActivity().getPackageManager(); final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0; if (cameraAvailable) options.add(fragment.getString(R.string.actfm_picture_camera)); options.add(fragment.getString(R.string.actfm_picture_gallery)); if (clearImageOption != null) options.add(fragment.getString(R.string.actfm_picture_clear)); ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(), android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()])); DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @SuppressWarnings("nls") @Override/*from w w w. j ava2s . co m*/ public void onClick(DialogInterface d, int which) { if (which == 0 && cameraAvailable) { lastTempFile = getTempFile(fragment.getActivity()); if (lastTempFile != null) cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile)); fragment.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); fragment.startActivityForResult( Intent.createChooser(intent, fragment.getString(R.string.actfm_TVA_tag_picture)), REQUEST_CODE_PICTURE); } else { if (clearImageOption != null) clearImageOption.clearImage(); } } }; // show a menu of available options new AlertDialog.Builder(fragment.getActivity()).setAdapter(adapter, listener).show() .setOwnerActivity(fragment.getActivity()); }
From source file:io.hypertrack.sendeta.util.images.EasyImage.java
private static Intent createCameraIntent(Context context) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); try {//from w w w.j a v a 2 s . com Uri capturedImageUri = createCameraPictureFile(context); intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri); } catch (Exception e) { e.printStackTrace(); } return intent; }
From source file:Fragments.VerificationFragment.java
private void changeProfilePicture() { /* Intent intent = new Intent(); /*www .j av a 2 s . co m*/ intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent,"Select file to upload "), 0);*/ final CharSequence options[] = new CharSequence[] { "Take Photo", "Choose from Library", "Cancel" }; android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( this.getActivity()); builder.setCancelable(false); builder.setTitle("Select your option:"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { // the user clicked on options[which] if (options[item].equals("Take Photo")) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0); } else if (options[item].equals("Choose from Library")) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), 1); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:com.manning.androidhacks.hack035.MainActivity.java
public void onPickBoth(View v) { Intent pickIntent = new Intent(Intent.ACTION_GET_CONTENT); pickIntent.setType("image/*"); Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent chooserIntent = Intent.createChooser(pickIntent, getString(R.string.activity_main_pick_both)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent }); startActivityForResult(chooserIntent, PICK_OR_TAKE_PICTURE); }
From source file:org.telegram.ui.Components.WallpaperUpdater.java
public void showAlert(final boolean fromTheme) { AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); CharSequence[] items;//from w w w .j av a2 s . c om if (fromTheme) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("SelectColor", R.string.SelectColor), LocaleController.getString("Default", R.string.Default), LocaleController.getString("Cancel", R.string.Cancel) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { if (i == 0) { try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = AndroidUtilities.generatePicturePath(); if (image != null) { if (Build.VERSION.SDK_INT >= 24) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile( parentActivity, BuildConfig.APPLICATION_ID + ".provider", image)); takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); } currentPicturePath = image.getAbsolutePath(); } parentActivity.startActivityForResult(takePictureIntent, 10); } catch (Exception e) { FileLog.e(e); } } else if (i == 1) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); parentActivity.startActivityForResult(photoPickerIntent, 11); } else if (fromTheme) { if (i == 2) { delegate.needOpenColorPicker(); } else if (i == 3) { delegate.didSelectWallpaper(null, null); } } } catch (Exception e) { FileLog.e(e); } } }); builder.show(); }
From source file:com.yozio.demo.implementations.twitter.TweetPhotoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.photo);//from ww w . j a v a 2s. c om Button btnPhoto = (Button) findViewById(R.id.btnPhoto); btnPostPhoto = (Button) findViewById(R.id.btnPostPhoto); mImageView = (ImageView) findViewById(R.id.imgPhoto); btnPhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePictureIntent, 0); } }); // This does the post to twitter btnPostPhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mImageBitmap != null) { final ProgressDialog progress = SafeProgressDialog.show(TweetPhotoActivity.this); // First create a Socialize share object so we get the correct URLs ShareOptions options = ShareUtils.getUserShareOptions(TweetPhotoActivity.this); ShareUtils.registerShare(TweetPhotoActivity.this, entity, options, new ShareAddListener() { @Override public void onError(SocializeException error) { progress.dismiss(); handleError(TweetPhotoActivity.this, error); } @Override public void onCreate(Share result) { // Now post to Twitter. try { // Get the bytes for the image byte[] image = TwitterUtils.getImageForPost(TweetPhotoActivity.this, mImageBitmap, CompressFormat.JPEG); PhotoTweet tweet = new PhotoTweet(); tweet.setImageData(image); String link = "http://www.trybluebug.com"; tweet.setText("Taken with BlueBug " + link); TwitterUtils.tweetPhoto(TweetPhotoActivity.this, tweet, new SocialNetworkPostListener() { @Override public void onNetworkError(Activity context, SocialNetwork network, Exception error) { progress.dismiss(); handleError(TweetPhotoActivity.this, error); } @Override public void onCancel() { progress.dismiss(); DemoUtils.showToast(TweetPhotoActivity.this, "Cancelled"); } @Override public void onAfterPost(Activity parent, SocialNetwork socialNetwork, JSONObject responseObject) { progress.dismiss(); DemoUtils.showToast(parent, "Photo Shared!"); } }); } catch (IOException e) { handleError(TweetPhotoActivity.this, e); } } }, SocialNetwork.TWITTER); } } }); }
From source file:com.yozio.demo.implementations.facebook.PostPhotoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.photo);//from w ww .jav a 2s . c o m Button btnPhoto = (Button) findViewById(R.id.btnPhoto); btnPostPhoto = (Button) findViewById(R.id.btnPostPhoto); mImageView = (ImageView) findViewById(R.id.imgPhoto); btnPhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePictureIntent, 0); } }); // This does the post to facebook btnPostPhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mImageBitmap != null) { final ProgressDialog progress = SafeProgressDialog.show(PostPhotoActivity.this); // First create a Socialize share object so we get the correct URLs ShareOptions options = ShareUtils.getUserShareOptions(PostPhotoActivity.this); ShareUtils.registerShare(PostPhotoActivity.this, entity, options, new ShareAddListener() { @Override public void onError(SocializeException error) { progress.dismiss(); handleError(PostPhotoActivity.this, error); } @Override public void onCreate(Share result) { // Now post to Facebook. try { // Get the bytes for the image byte[] image = FacebookUtils.getImageForPost(PostPhotoActivity.this, mImageBitmap, CompressFormat.JPEG); Map<String, Object> params = new HashMap<String, Object>(); String graphPath = "me/photos"; String link = "http://www.trybluebug.com"; String msg = "Taken with BlueBug " + link; params.put("caption", msg); params.put("photo", image); FacebookUtils.post(PostPhotoActivity.this, graphPath, params, new SocialNetworkPostListener() { @Override public void onNetworkError(Activity context, SocialNetwork network, Exception error) { progress.dismiss(); handleError(PostPhotoActivity.this, error); } @Override public void onCancel() { progress.dismiss(); DemoUtils.showToast(PostPhotoActivity.this, "Cancelled"); } @Override public void onAfterPost(Activity parent, SocialNetwork socialNetwork, JSONObject responseObject) { progress.dismiss(); DemoUtils.showToast(parent, "Photo Shared!"); } }); } catch (IOException e) { handleError(PostPhotoActivity.this, e); } } }, SocialNetwork.FACEBOOK); } } }); }
From source file:mysteryinc.eagleeye.LiveLocatorFragment.java
/** * Start the camera by dispatching a camera intent. Returns a string location to the photo. *///from w w w .j a va 2s . c om private String takePicture() { // Check if there is a camera. if (deviceMissingCamera()) { MainActivity.toast("This device does not have a camera."); return ""; } // Camera exists? Then proceed... Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent Activity activity = getActivity(); File photoFile = null; if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) { // Create the File where the photo should go. // If you don't do this, you may get a crash in some devices. try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File ex.printStackTrace(); MainActivity.toast("There was a problem saving the photo..."); } // Continue only if the File was successfully created if (photoFile != null) { Uri fileUri = Uri.fromFile(photoFile); // activity.setCapturedImageURI(fileUri); // activity.setCurrentPhotoPath(fileUri.getPath()); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // activity.getCapturedImageURI()); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } return photoFile.getAbsolutePath(); }
From source file:it.geosolutions.geocollect.android.core.form.action.CameraAction.java
@Override public void performAction(SherlockFragment fragment, FormAction action, Mission m, Page p) { String originIDString = MissionUtils.getMissionGCID(m); if (originIDString == null || originIDString.isEmpty()) { Log.w("CameraAction", "Could not start intent, feature id not found"); return;/*from w ww . j a va 2s . c o m*/ } // create Intent to take a picture and return control to the calling application Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE, originIDString); // create a file to save the image if (fileUri != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name // start the image capture Intent fragment.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } else { Log.w("CameraAction", "Could not start intent, bad Uri"); } }
From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java
private static String capturePictureLabel(Context context, IStartable startable) { // Starts a picture intent. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) { File photoFile = null;//from w w w . ja v a2 s . co m try { photoFile = PictureUtils.createImageFile( AppSingleton.getInstance(context).getSensorEnvironment().getDefaultClock().getNow()); } catch (IOException ex) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, ex.getMessage()); } } if (photoFile != null) { Uri photoUri = FileProvider.getUriForFile(context, context.getPackageName(), photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Needed to avoid security exception on KitKat. takePictureIntent.setClipData(ClipData.newRawUri(null, photoUri)); } takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); String pictureLabelPath = "file:" + photoFile.getAbsoluteFile(); startable.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); return pictureLabelPath; } } return null; }