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.android.common.util.IntentUtils.java
/** * Open camera//from ww w.java 2 s .co m * * @param context */ public static void openCamera(Context context) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); context.startActivity(intent); }
From source file:com.univpm.s1055802.faceplusplustester.Detect.AcquirePhoto.java
/** * Richiama la fotocamera, acquisisce la foto e la salva in un file * @return il file salvato/*from w w w . ja va2 s . co m*/ */ private void Acquire() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent photoFile = null; if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File Log.v("alert", "file error"); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:com.google.android.gms.samples.vision.face.photo.PhotoViewerActivity.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); } catch (IOException ex) { }/*from w w w . j a v a 2s .co m*/ // Continue only if the File was successfully created if (photoFile != null) { photoURI = Uri.fromFile(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } } }
From source file:com.luyaozhou.recognizethisforglass.ViewFinder.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_CAMERA: { // camera button (hardware) if (keyEnable) { camera.stopPreview(); // stop the preview camera.release(); // release the camera previewOn = false;/*w w w.ja va2s . c om*/ keyEnable = false; mHandler.post(new Runnable() { @Override public void run() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // capture image if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, PHOTO_REQUEST_CODE); } } }); } // Return false to allow the camera button to do its default action return false; } case KeyEvent.KEYCODE_DPAD_CENTER: // touchpad tap case KeyEvent.KEYCODE_ENTER: { if (keyEnable) { camera.stopPreview(); camera.release(); previewOn = false; // Don't release the camera in surfaceDestroyed() keyEnable = false; mHandler.post(new Runnable() { @Override public void run() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // capture image if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, PHOTO_REQUEST_CODE); } } }); } return false; } default: { return super.onKeyDown(keyCode, event); } } }
From source file:com.app.ecofriend.ecofriend.DisplayMessageActivity.java
private void takePicture() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg"); imageUri = Uri.fromFile(photo);/* ww w . j a va 2 s.c om*/ intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, PHOTO_REQUEST); }
From source file:com.allen.mediautil.ImageTakerHelper.java
/** * ?// w w w. j a v a 2s .c om * <p> * onActivityResult()? */ public static void openCamera(Activity activity, String authority) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputPictureUri(activity.getApplicationContext(), authority)); activity.startActivityForResult(intent, REQUEST_CAMERA); }
From source file:com.king.base.util.SystemUtils.java
/** * ?//from w ww. j a v a 2 s . com * * @param activity * @param path * @param requestCode */ public static void imageCapture(Activity activity, 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(activity, activity.getPackageName() + ".fileProvider", new File(path)); } else { uri = Uri.fromFile(new File(path)); } intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); } activity.startActivityForResult(intent, requestCode); }
From source file:com.openerp.base.ir.Attachment.java
public void requestAttachment(Types type) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); switch (type) { case IMAGE_OR_CAPTURE_IMAGE: // createDialog(type); // break; case IMAGE:/*from ww w . j a v a 2 s.c o m*/ intent.setType("image/*"); requestIntent(intent, REQUEST_IMAGE); break; case CAPTURE_IMAGE: intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); requestIntent(intent, REQUEST_CAMERA); break; case AUDIO: intent.setType("audio/*"); requestIntent(intent, REQUEST_AUDIO); break; case FILE: intent.setType("application/file"); requestIntent(intent, REQUEST_FILE); break; default: break; } }
From source file:com.android.common.util.IntentUtils.java
/** * Take camera, this photo data will be returned in onActivityResult() * * @param activity/*from www . j a va 2s . c om*/ * @param requestCode */ public static void takeCamera(Activity activity, int requestCode) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); activity.startActivityForResult(intent, requestCode); }
From source file:org.odk.collect.android.widgets.ImageWidget.java
public ImageWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent(); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5);/*w w w . j av a2s . co m*/ mErrorTextView = new TextView(context); mErrorTextView.setId(QuestionWidget.newUniqueId()); mErrorTextView.setText("Selected file is not a valid image"); // setup capture button mCaptureButton = new Button(getContext()); mCaptureButton.setId(QuestionWidget.newUniqueId()); mCaptureButton.setText(getContext().getString(R.string.capture_image)); mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mCaptureButton.setPadding(20, 20, 20, 20); mCaptureButton.setEnabled(!prompt.isReadOnly()); mCaptureButton.setLayoutParams(params); // launch capture intent on click mCaptureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); // We give the camera an absolute filename/path where to put the // picture because of bug: // http://code.google.com/p/android/issues/detail?id=1480 // The bug appears to be fixed in Android 2.0+, but as of feb 2, // 2010, G1 phones only run 1.6. Without specifying the path the // images returned by the camera in 1.6 (and earlier) are ~1/4 // the size. boo. // if this gets modified, the onActivityResult in // FormEntyActivity will also need to be updated. i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", new File(Collect.TMPFILE_PATH))); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, "image capture"), Toast.LENGTH_SHORT).show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // setup chooser button mChooseButton = new Button(getContext()); mChooseButton.setId(QuestionWidget.newUniqueId()); mChooseButton.setText(getContext().getString(R.string.choose_image)); mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mChooseButton.setPadding(20, 20, 20, 20); mChooseButton.setEnabled(!prompt.isReadOnly()); mChooseButton.setLayoutParams(params); // launch capture intent on click mChooseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT) .show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // finish complex layout LinearLayout answerLayout = new LinearLayout(getContext()); answerLayout.setOrientation(LinearLayout.VERTICAL); answerLayout.addView(mCaptureButton); answerLayout.addView(mChooseButton); answerLayout.addView(mErrorTextView); // and hide the capture and choose button if read-only if (prompt.isReadOnly()) { mCaptureButton.setVisibility(View.GONE); mChooseButton.setVisibility(View.GONE); } mErrorTextView.setVisibility(View.GONE); // retrieve answer from data model and update ui mBinaryName = prompt.getAnswerText(); // Only add the imageView if the user has taken a picture if (mBinaryName != null) { mImageView = new ImageView(getContext()); mImageView.setId(QuestionWidget.newUniqueId()); Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); File f = new File(mInstanceFolder + File.separator + mBinaryName); if (f.exists()) { Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth); if (bmp == null) { mErrorTextView.setVisibility(View.VISIBLE); } mImageView.setImageBitmap(bmp); } else { mImageView.setImageBitmap(null); } mImageView.setPadding(10, 10, 10, 10); mImageView.setAdjustViewBounds(true); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "viewButton", "click", mPrompt.getIndex()); Intent i = new Intent("android.intent.action.VIEW"); Uri uri = MediaUtils .getImageUriFromMediaProvider(mInstanceFolder + File.separator + mBinaryName); if (uri != null) { Log.i(t, "setting view path to: " + uri); i.setDataAndType(uri, "image/*"); try { getContext().startActivity(i); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, "view image"), Toast.LENGTH_SHORT).show(); } } } }); answerLayout.addView(mImageView); } addAnswerView(answerLayout); }