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.sat.sonata.MenuActivity.java
private void takePicture() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, TAKE_PICTURE_REQUEST); }
From source file:eu.geopaparazzi.library.camera.AbstractCameraActivity.java
protected void doTakePicture(Bundle icicle) { Bundle extras = getIntent().getExtras(); File imageSaveFolder = null;//from w ww .j av a 2 s. c o m try { imageSaveFolder = ResourcesManager.getInstance(this).getTempDir(); String imageName; if (extras != null) { String imageSaveFolderTmp = extras.getString(LibraryConstants.PREFS_KEY_CAMERA_IMAGESAVEFOLDER); if (imageSaveFolderTmp != null && new File(imageSaveFolderTmp).exists()) { imageSaveFolder = new File(imageSaveFolderTmp); } imageName = extras.getString(LibraryConstants.PREFS_KEY_CAMERA_IMAGENAME); } else { throw new RuntimeException("Not implemented yet..."); } if (!imageSaveFolder.exists()) { if (!imageSaveFolder.mkdirs()) { Runnable runnable = new Runnable() { public void run() { finish(); } }; GPDialogs.warningDialog(this, getString(R.string.cantcreate_img_folder), runnable); return; } } File mediaFolder = imageSaveFolder; currentDate = new Date(); if (imageName == null) { imageName = ImageUtilities.getCameraImageName(currentDate); } imageFilePath = mediaFolder.getAbsolutePath() + File.separator + imageName; File imgFile = new File(imageFilePath); Uri outputFileUri = Utilities.getFileUriInApplicationFolder(this, imgFile); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); lastImageMediastoreId = getLastImageMediaId(); startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } catch (Exception e) { GPLog.error(this, null, e); GPDialogs.errorDialog(this, e, new Runnable() { @Override public void run() { finish(); } }); } }
From source file:com.microsoft.projectoxford.visionsample.helper.SelectImageActivity.java
public void takePhoto(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { // Save the photo taken to a temporary file. File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); try {//w w w. java2 s . c o m mFilePhotoTaken = File.createTempFile("IMG_", /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Create the File where the photo should go // Continue only if the File was successfully created if (mFilePhotoTaken != null) { mUriPhotoTaken = FileProvider.getUriForFile(this, "com.microsoft.projectoxford.visionsample.fileprovider", mFilePhotoTaken); intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken); // Finally start camera activity startActivityForResult(intent, REQUEST_TAKE_PHOTO); } } catch (IOException e) { setInfo(e.getMessage()); } } }
From source file:com.monmonja.library.social.SocialNetworkDialogFragment.java
/** * Start the camera by dispatching a camera intent. */ protected void dispatchTakePictureIntent() { PackageManager packageManager = getActivity().getPackageManager(); if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show(); return;/* ww w . java 2s. c o m*/ } Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { try { File tempFile = getTempCaptureImgPath(); mTempTakePicturePath = tempFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } catch (IOException ex) { } } }
From source file:com.king.base.util.SystemUtils.java
/** * ?/*from www . j av a 2 s . com*/ * * @param fragment * @param path * @param requestCode */ public static void imageCapture(Fragment fragment, String path, int requestCode) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (!TextUtils.isEmpty(path)) { Uri uri = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { uri = FileProvider.getUriForFile(fragment.getContext(), fragment.getContext().getPackageName() + ".fileProvider", new File(path)); } else { uri = Uri.fromFile(new File(path)); } intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); } fragment.startActivityForResult(intent, requestCode); }
From source file:com.ez.gallery.PhotoBaseActivity.java
/** * ?//w ww . j a v a 2 s. co m */ protected void takePhotoAction() { if (!DeviceUtils.existSDCard()) { String errormsg = getString(R.string.empty_sdcard); toast(errormsg); if (mTakePhotoAction) { resultFailure(errormsg, true); } return; } File takePhotoFolder; if (StringUtils.isEmpty(mPhotoTargetFolder)) { takePhotoFolder = Picseler.getCoreConfig().getTakePhotoFolder(); } else { takePhotoFolder = new File(mPhotoTargetFolder); } boolean suc = FileUtils.mkdirs(takePhotoFolder); File toFile = new File(takePhotoFolder, "IMG" + DateUtils.format(new Date(), "yyyyMMddHHmmss") + ".jpg"); if (suc) { mTakePhotoUri = Uri.fromFile(toFile); Uri uri = FileProvider.getUriForFile(this, Picseler.getCoreConfig().getFileProvider(), toFile);//FileProvidercontentUri Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(captureIntent, Picseler.TAKE_REQUEST_CODE); } else { takePhotoFailure(); } }
From source file:com.bilibili.boxing.utils.CameraPickerHelper.java
private boolean takePhotoSecure(Activity activity, Fragment fragment, String subDir) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { try {/*from ww w. j av a 2 s.c o m*/ startCameraIntent(activity, fragment, subDir, MediaStore.ACTION_IMAGE_CAPTURE, REQ_CODE_CAMERA); return true; } catch (ActivityNotFoundException ignore) { return false; } } return false; }
From source file:camera.AnotherCamera.java
/** * Start the camera by dispatching a camera intent. *///from w w w . j a v a2 s . c o m protected void dispatchTakePictureIntent() { // Check if there is a camera. Context context = getActivity(); PackageManager packageManager = context.getPackageManager(); if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) { Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show(); return; } // Camera exists? Then proceed... Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent CameraActivity activity = (CameraActivity) getActivity(); 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. File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File Toast toast = Toast.makeText(activity, "There was a problem saving the photo...", Toast.LENGTH_SHORT); toast.show(); } // 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, activity.getCapturedImageURI()); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:ca.cmput301f13t03.adventure_datetime.view.FullScreen_Image.java
private void setUpView() { if (_fragment == null) return;//from w ww .j a v a2 s . c om if (_pageAdapter == null) return; Button gallery = (Button) findViewById(R.id.gallery); Button camera = (Button) findViewById(R.id.camera); Button delete = (Button) findViewById(R.id.action_delete); gallery.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, GALLERY); } }); camera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { File picDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "adventure.datetime"); if (!picDir.exists()) picDir.mkdirs(); File pic = new File(picDir.getPath(), File.separator + _fragment.getFragmentID().toString() + "-" + _fragment.getStoryMedia().size()); _newImage = Uri.fromFile(pic); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, _newImage); startActivityForResult(i, CAMERA); } }); _pageAdapter.setIllustrations(_fragment.getStoryMedia(), getIntent().getBooleanExtra(TAG_AUTHOR, false)); /* ArrayList<String> list = new ArrayList<String>(); for (int i=0; i<5; i++) list.add(""+i); _pageAdapter.setIllustrations(list, getIntent(). getBooleanExtra(TAG_AUTHOR, false));*/ }
From source file:com.happiestminds.template.ui.activity.ItemDetailActivity.java
public void onButtonClick(View v) { //Crop.pickImage(this); final CharSequence[] items = { ImageCaptureType.CAPTURE_BY_CAMERA.toString(), ImageCaptureType.CAPTURE_BY_CAMERA_WITHCROP.toString(), ImageCaptureType.CAPTURE_BY_GALLERY.toString(), ImageCaptureType.CAPTURE_BY_GALLERY_WITHCROP.toString(), "Download Image", ImageCaptureType.CAPTURE_BY_CAMERA_ORIGINAL.toString() }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Make your selection"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: ImageServices.imageCapture(ItemDetailActivity.this, ImageCaptureType.CAPTURE_BY_CAMERA); break; case 1: ImageServices.imageCapture(ItemDetailActivity.this, ImageCaptureType.CAPTURE_BY_CAMERA_WITHCROP); break; case 2: ImageServices.imageCapture(ItemDetailActivity.this, ImageCaptureType.CAPTURE_BY_GALLERY); break; case 3: ImageServices.imageCapture(ItemDetailActivity.this, ImageCaptureType.CAPTURE_BY_GALLERY_WITHCROP); break; case 4: ImageServices.displayImageFromUrl( "http://farm6.staticflickr.com/5344/9049177018_4621cb63db_s.jpg", imageView); break; case 5: imageUri = ImageServices.getOutputMediaFileUri(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, ImageCaptureType.CAPTURE_BY_CAMERA_ORIGINAL.getImageCaptureType()); break; }//from ww w . ja v a2s .c om } }); AlertDialog alert = builder.create(); alert.show(); }