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:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java
/** * Displays dialog and either launches camera or gallery * /*from w w w. j a va2s .c om*/ * @param view * the AttachPhoto button in postThreadFragment. */ public void attachImage(View view) { if (view.getId() == R.id.attach_image_button) { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle(R.string.attach_image_title); dialog.setMessage(R.string.attach_image_dialog); dialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { FavouritesFragment favFrag = (FavouritesFragment) getParentFragment(); boolean fromFav; if (favFrag != null) { fromFav = true; } else { fromFav = false; } Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); if (fromFav == true) { arg0.dismiss(); getParentFragment().startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_GALLERY); } else { arg0.dismiss(); startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_GALLERY); } } }); dialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { FavouritesFragment favFrag = (FavouritesFragment) getParentFragment(); boolean fromFav; if (favFrag != null) { fromFav = true; } else { fromFav = false; } Intent intent = new Intent(); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); try { imageFile = ImageHelper.createImageFile(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); if (fromFav == true) { arg0.dismiss(); getParentFragment().startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_CAMERA); } else { arg0.dismiss(); startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_CAMERA); } } catch (IOException e) { e.printStackTrace(); } } }); dialog.show(); } }
From source file:com.pizidea.imagepicker.util.AndroidImagePicker.java
/** * take picture/*from w ww . j av a 2 s .c o m*/ */ public void takePicture(Fragment fragment, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(fragment.getContext().getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(fragment.getContext()); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath()); } } fragment.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.nutsuser.ridersdomain.activities.LiveforDream.java
/** * Image Selection from Gallery or Camera **//*w w w . j a va 2 s. c o m*/ private void selectImage() { final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(LiveforDream.this); builder.setTitle("Add Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (items[item].equals("Take Photo")) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePictureIntent, ApplicationGlobal.CAMERA_REQUEST); } else if (items[item].equals("Choose from Library")) { Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, ApplicationGlobal.RESULT_LOAD_IMAGE); } else if (items[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:com.mobility.android.ui.vehicle.AddVehicleActivity.java
private void takePicture() { imageFile = new File(getExternalCacheDir(), System.currentTimeMillis() + ".jpg"); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); startActivityForResult(intent, CAMERA_REQUEST); }
From source file:com.hplasplas.cam_capture.activitys.CamCapture.java
public void makePhoto() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); mCurrentPictureFile = FileSystemManager.generateFileForPicture(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCurrentPictureFile)); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, GET_PICTURE_REQUEST_CODE); }// ww w. j a va2 s . c om }
From source file:com.nextgis.ngm_clink_monitoring.fragments.ObjectStatusFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MainActivity activity = (MainActivity) getActivity(); View view = inflater.inflate(R.layout.fragment_object_status, null); mLineName = (TextView) view.findViewById(R.id.line_name_st); mObjectNameCaption = (TextView) view.findViewById(R.id.object_name_caption_st); mObjectName = (TextView) view.findViewById(R.id.object_name_st); mCompleteStatusButton = (Button) view.findViewById(R.id.complete_status_st); mPhotoHintText = (TextView) view.findViewById(R.id.photo_hint_text_st); mMakePhotoButton = (Button) view.findViewById(R.id.btn_make_photo_st); mPhotoGallery = (RecyclerView) view.findViewById(R.id.photo_gallery_st); registerForContextMenu(mPhotoGallery); String toolbarTitle = ""; switch (mFoclStructLayerType) { case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CABLE: toolbarTitle = activity.getString(R.string.cable_laying); mObjectNameCaption.setText(R.string.optical_cable_colon); break;/*from w ww . j av a2 s. c om*/ case FoclConstants.LAYERTYPE_FOCL_FOSC: toolbarTitle = activity.getString(R.string.fosc_mounting); mObjectNameCaption.setText(R.string.fosc_colon); break; case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CROSS: toolbarTitle = activity.getString(R.string.cross_mounting); mObjectNameCaption.setText(R.string.cross_colon); break; case FoclConstants.LAYERTYPE_FOCL_ACCESS_POINT: toolbarTitle = activity.getString(R.string.access_point_mounting); mObjectNameCaption.setText(R.string.access_point_colon); break; case FoclConstants.LAYERTYPE_FOCL_SPECIAL_TRANSITION: toolbarTitle = activity.getString(R.string.special_transition_laying); break; } activity.setBarsView(toolbarTitle); mCompleteStatusButton.setText(activity.getString(R.string.completed)); mPhotoHintText.setText(R.string.take_photos_to_confirm); final GISApplication app = (GISApplication) getActivity().getApplication(); final FoclProject foclProject = app.getFoclProject(); if (null == foclProject) { setBlockedView(); return view; } FoclStruct foclStruct; try { foclStruct = (FoclStruct) foclProject.getLayer(mLineId); } catch (Exception e) { foclStruct = null; } if (null == foclStruct) { setBlockedView(); return view; } FoclVectorLayer layer = (FoclVectorLayer) foclStruct.getLayerByFoclType(mFoclStructLayerType); if (null == layer) { setBlockedView(); return view; } if (null == mObjectId) { setBlockedView(); return view; } mLineName.setText(Html.fromHtml(foclStruct.getHtmlFormattedNameTwoStringsSmall())); mObjectLayerName = layer.getPath().getName(); Uri uri = Uri .parse("content://" + FoclSettingsConstantsUI.AUTHORITY + "/" + mObjectLayerName + "/" + mObjectId); String proj[] = { FIELD_ID, FoclConstants.FIELD_NAME, FoclConstants.FIELD_STATUS_BUILT }; Cursor objectCursor; try { objectCursor = getActivity().getContentResolver().query(uri, proj, null, null, null); } catch (Exception e) { Log.d(TAG, e.getLocalizedMessage()); objectCursor = null; } boolean blockView = false; if (null != objectCursor) { try { if (objectCursor.getCount() == 1 && objectCursor.moveToFirst()) { String objectNameText = ObjectCursorAdapter.getObjectName(mContext, objectCursor); mObjectStatus = objectCursor .getString(objectCursor.getColumnIndex(FoclConstants.FIELD_STATUS_BUILT)); if (TextUtils.isEmpty(mObjectStatus)) { mObjectStatus = FoclConstants.FIELD_VALUE_UNKNOWN; } mObjectName.setText(objectNameText); setStatusButtonView(true); } else { blockView = true; } } catch (Exception e) { blockView = true; //Log.d(TAG, e.getLocalizedMessage()); } finally { objectCursor.close(); } } else { blockView = true; } if (blockView) { setBlockedView(); return view; } View.OnClickListener statusButtonOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { switch (mObjectStatus) { case FoclConstants.FIELD_VALUE_PROJECT: mObjectStatus = FoclConstants.FIELD_VALUE_BUILT; break; case FoclConstants.FIELD_VALUE_BUILT: mObjectStatus = FoclConstants.FIELD_VALUE_PROJECT; break; case FoclConstants.FIELD_VALUE_UNKNOWN: default: mObjectStatus = FoclConstants.FIELD_VALUE_BUILT; break; } Uri uri = Uri.parse("content://" + FoclSettingsConstantsUI.AUTHORITY + "/" + mObjectLayerName); Uri updateUri = ContentUris.withAppendedId(uri, mObjectId); ContentValues values = new ContentValues(); Calendar calendar = Calendar.getInstance(); values.put(FoclConstants.FIELD_STATUS_BUILT, mObjectStatus); values.put(FoclConstants.FIELD_STATUS_BUILT_CH, calendar.getTimeInMillis()); int result = 0; try { result = getActivity().getContentResolver().update(updateUri, values, null, null); } catch (Exception e) { Log.d(TAG, e.getLocalizedMessage()); } if (result == 0) { Log.d(TAG, "Layer: " + mObjectLayerName + ", id: " + mObjectId + ", update FAILED"); } else { Log.d(TAG, "Layer: " + mObjectLayerName + ", id: " + mObjectId + ", update result: " + result); setStatusButtonView(true); } } }; ActionBar actionBar = activity.getSupportActionBar(); if (actionBar != null) { View customActionBarView = actionBar.getCustomView(); View saveMenuItem = customActionBarView.findViewById(R.id.custom_toolbar_button_layout); saveMenuItem.setOnClickListener(statusButtonOnClickListener); // TODO: it is test } mCompleteStatusButton.setOnClickListener(statusButtonOnClickListener); mMakePhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (null != cameraIntent.resolveActivity(getActivity().getPackageManager())) { try { File tempFile = new File(app.getDataDir(), "temp-photo.jpg"); if (!tempFile.exists() && tempFile.createNewFile() || tempFile.exists() && tempFile.delete() && tempFile.createNewFile()) { mTempPhotoPath = tempFile.getAbsolutePath(); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); startActivityForResult(cameraIntent, REQUEST_TAKE_PHOTO); } } catch (IOException e) { Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } } }); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); mPhotoGallery.setLayoutManager(layoutManager); mPhotoGallery.setHasFixedSize(true); setPhotoGalleryAdapter(); setPhotoGalleryVisibility(true); return view; }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
public void photoClicked(View view) { File file = makePhotoFile();//from w ww. ja va 2 s. co m if (file == null) return; Uri outputFileUri = Uri.fromFile(file); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, Constants.ACTIVITY_CAMERA); }
From source file:com.salmannazir.filemanager.businesslogic.EventHandler.java
private void showNewImageCreateDialog(final Activity mContext, final String directory) { boolean wrapInScrollView = true; new MaterialDialog.Builder(mContext).title("Create New Image File") .customView(R.layout.new_image_layout, wrapInScrollView).positiveText("Capture Image") .negativeText("Cancel").onPositive(new MaterialDialog.SingleButtonCallback() { @Override//from w w w . j a va 2 s . com public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { // TODO Toast.makeText(mContext, "+ve Clicked", Toast.LENGTH_SHORT).show(); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (cameraIntent.resolveActivity(mContext.getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { EditText imageNameEditText = (EditText) dialog.findViewById(R.id.image_name); photoFile = createImageFile(imageNameEditText.getText().toString(), directory); } catch (IOException ex) { // Error occurred while creating the File Log.i("MainActivity", "IOException"); } // Continue only if the File was successfully created if (photoFile != null) { cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); mContext.startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST); } } } }).show(); }
From source file:com.app_software.chromisstock.ProductDetailFragment.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }/*w ww. ja v a2 s .c o m*/ }
From source file:com.concavenp.artistrymuse.ImageAppCompatActivity.java
protected void dispatchTakePictureIntent() { 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 = createImageFile(); // Continue only if the File was successfully created if (photoFile != null) { Uri photoURI = FileProvider.getUriForFile(this, "com.concavenp.artistrymuse", photoFile); Log.d(TAG, "New camera image URI location: " + photoURI.toString()); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }/* ww w . ja v a 2 s. c o m*/ } }