Example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE

List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE

Introduction

In this page you can find the example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Prototype

String ACTION_IMAGE_CAPTURE

To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Click Source Link

Document

Standard Intent action that can be sent to have the camera application capture an image and return it.

Usage

From source file:com.zfb.house.emchat.ChatActivity.java

/**
 * ?/*w w  w  .  j av  a 2  s . c o m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        String st = getResources().getString(R.string.sd_card_does_not_exist);
        Toast.makeText(getApplicationContext(), st, Toast.LENGTH_SHORT).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            UserBean.getInstance(this).name/*DemoApplication.getInstance().getUserName()*/
                    + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:org.smilec.smile.student.CourseList.java

private void takepicture() {

    chkimg = 1;/* w  w  w . j ava2  s .  co  m*/
    TakenImage = false;

    // check if external storage exist
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but all we need
        //  to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if (mExternalStorageAvailable == false || mExternalStorageWriteable == false) {
        showToast("We cannot take picture. Please check if the external storage available or writeable.");
        return;
    }

    // -----------------------------------------------------------------
    // Start Built-in Camera Activity
    // -----------------------------------------------------------------
    // define the file-name to save photo taken by Camera activity
    String img_filename = "new-photo-name.jpg";
    // create parameters for Intent with filename
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, img_filename);
    values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
    // imageUri is the current activity attribute, define and save it for
    // later usage (also in onSaveInstanceState)
    imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    // imageUri =
    // getContentResolver().insert(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
    // values);

    // create new Intent
    camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    camera_intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

    startActivityForResult(camera_intent, IMAGECAPTURE_OK);

}

From source file:cn.yunluosoft.tonglou.activity.ChatActivity.java

/**
 * ?/*from  www. ja  v a 2 s.co m*/
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        String st = getResources().getString(R.string.sd_card_does_not_exist);
        Toast.makeText(getApplicationContext(), st, Toast.LENGTH_SHORT).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            MyApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:com.almalence.opencam.PluginManager.java

/******************************************************************************************************
 * Message handler//w ww  . ja va2  s.c o m
 ******************************************************************************************************/
@Override
public boolean handleApplicationMessage(Message msg) {
    long sessionID = 0;

    switch (msg.what) {
    case ApplicationInterface.MSG_NO_CAMERA:
        break;

    case ApplicationInterface.MSG_CAPTURE_FINISHED:
        shutterRelease = true;

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (CameraController.getFocusMode() == CameraParameters.AF_MODE_CONTINUOUS_PICTURE) {
            CameraController.cancelAutoFocus();
        }

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        // Returns actual flash mode if it was changed during capturing.
        if (!CameraController.isUseCamera2()) {
            int flashMode = ApplicationScreen.instance.getFlashModePref(ApplicationScreen.sDefaultFlashValue);
            if (flashMode != CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
                CameraController.setCameraFlashMode(flashMode);
            }
        }

        int id = ApplicationScreen.getAppResources().getIdentifier(getActiveMode().modeName, "string",
                ApplicationScreen.instance.getPackageName());
        String modeName = ApplicationScreen.getAppResources().getString(id);
        addToSharedMem("mode_name" + (String) msg.obj, modeName);
        // start async task for further processing
        cntProcessing++;

        sessionID = Long.valueOf((String) msg.obj);

        // Map sessionID and processing plugin, because active plugin may be
        // changed before image processing will start (Mode was switched).
        // We don't map export plugin, because it's the same for all modes.
        processingPluginList.put(sessionID, pluginList.get(activeProcessing));

        Intent mServiceIntent = new Intent(ApplicationScreen.instance, ProcessingService.class);

        // Pass to Service sessionID and some other parameters, that may be required.
        mServiceIntent.putExtra("sessionID", sessionID);
        CameraController.Size imageSize = CameraController.getCameraImageSize();
        PluginManager.getInstance().addToSharedMem("imageWidth" + sessionID,
                String.valueOf(imageSize.getWidth()));
        PluginManager.getInstance().addToSharedMem("imageHeight" + sessionID,
                String.valueOf(imageSize.getHeight()));
        PluginManager.getInstance().addToSharedMem("wantLandscapePhoto" + sessionID,
                String.valueOf(ApplicationScreen.getWantLandscapePhoto()));
        PluginManager.getInstance().addToSharedMem("cameraMirrored" + sessionID,
                String.valueOf(CameraController.isFrontCamera()));

        // Start processing service with current sessionID.
        ApplicationScreen.instance.startService(mServiceIntent);

        ApplicationScreen.instance.muteShutter(false);

        // <!-- -+-
        // if mode free
        controlPremiumContent();
        // -+- -->

        if (!PluginManager.getInstance().getActiveModeID().equals("video")) {
            ApplicationScreen.getGUIManager().lockControls = false;
            PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                    ApplicationInterface.MSG_CONTROL_UNLOCKED);
        }

        break;

    case ApplicationInterface.MSG_CAPTURE_FINISHED_NORESULT:
        shutterRelease = true;

        /*
         * Debug code for Galaxy S6 in Super mode. Look at Camera2 for more
         * details
         */
        // CameraController.onCaptureFinished();

        if (CameraController.getFocusMode() == CameraParameters.AF_MODE_CONTINUOUS_PICTURE) {
            CameraController.cancelAutoFocus();
        }

        if (ApplicationScreen.instance.getFlashModePref(
                ApplicationScreen.sDefaultFlashValue) == CameraParameters.FLASH_MODE_CAPTURE_TORCH) {
            // If flashMode == FLASH_MODE_CAPTURE_TORCH, then turn off torch
            // after capturing completed.
            CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_OFF);
        }

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onCaptureFinished();

        ApplicationScreen.getGUIManager().onCaptureFinished();
        ApplicationScreen.getGUIManager().startProcessingAnimation();

        ApplicationScreen.instance.muteShutter(false);

        ApplicationScreen.getGUIManager().lockControls = false;

        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onExportFinished();

        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        break;

    case ApplicationInterface.MSG_START_POSTPROCESSING:
        if (null != pluginList.get(activeProcessing)) {
            ApplicationScreen.getGUIManager().lockControls = true;
            PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                    ApplicationInterface.MSG_CONTROL_LOCKED);

            pluginList.get(activeProcessing).onStartPostProcessing();
            ApplicationScreen.getGUIManager().onPostProcessingStarted();
        }
        break;

    case ApplicationInterface.MSG_POSTPROCESSING_FINISHED:
        sessionID = 0;
        String sSessionID = getFromSharedMem("sessionID");
        if (sSessionID != null)
            sessionID = Long.parseLong(getFromSharedMem("sessionID"));

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().lockControls = false;
        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().onPostProcessingFinished();
        if (null != pluginList.get(activeExport) && 0 != sessionID) {
            pluginList.get(activeExport).onExportActive(sessionID);
        } else {
            ApplicationScreen.getMessageHandler().sendEmptyMessage(ApplicationInterface.MSG_EXPORT_FINISHED);
            clearSharedMemory(sessionID);
        }
        break;
    case ApplicationInterface.MSG_EXPORT_FINISHED:
        getPrefs();

        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        if (ApplicationScreen.instance.getIntent().getAction() != null) {
            if (ApplicationScreen.instance.getIntent().getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)
                    && ApplicationScreen.getForceFilename() == null) {
                ApplicationScreen.getMessageHandler()
                        .sendEmptyMessage(ApplicationInterface.MSG_RETURN_CAPTURED);
            }
        }

        if (photoTimeLapseActive && photoTimeLapseIsRunning) {
            AlarmReceiver.getInstance().setNextAlarm(ApplicationScreen.instance.getApplicationContext());
            ApplicationScreen.instance.guiManager.showCaptureIndication();
        }
        break;

    case ApplicationInterface.MSG_EXPORT_FINISHED_IOEXCEPTION:
        getPrefs();

        // event from plugin that saving finished and memory can be freed
        if (cntProcessing > 0)
            cntProcessing--;
        // free memory in processing
        if (null != pluginList.get(activeProcessing))
            pluginList.get(activeProcessing).freeMemory();

        // notify GUI about saved images
        ApplicationScreen.getGUIManager().onExportFinished();

        // notify capture plugins that saving finished
        if (null != pluginList.get(activeCapture))
            pluginList.get(activeCapture).onExportFinished();
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onExportFinished();

        Toast.makeText(ApplicationScreen.getMainContext(), "Can't save data - seems no free space left.",
                Toast.LENGTH_LONG).show();

        if (photoTimeLapseActive && photoTimeLapseIsRunning) {
            AlarmReceiver.getInstance().setNextAlarm(ApplicationScreen.instance.getApplicationContext());
            ApplicationScreen.instance.guiManager.showCaptureIndication();
        }
        break;

    case ApplicationInterface.MSG_DELAYED_CAPTURE:
        for (int i = 0; i < activeVF.size(); i++)
            pluginList.get(activeVF.get(i)).onShutterClick();
        if (null != pluginList.get(activeCapture) && ApplicationScreen.instance
                .findViewById(R.id.postprocessingLayout).getVisibility() == View.GONE)
            pluginList.get(activeCapture).onShutterClick();
        break;

    case ApplicationInterface.MSG_RETURN_CAPTURED:
        ApplicationScreen.instance.setResult(Activity.RESULT_OK);
        ApplicationScreen.instance.finish();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW:
        ApplicationScreen.instance.showOpenGLLayer(1);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_SHOW_V2:
        ApplicationScreen.instance.showOpenGLLayer(2);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_HIDE:
        ApplicationScreen.instance.hideOpenGLLayer();
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_CONTINIOUS:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
        break;

    case ApplicationInterface.MSG_OPENGL_LAYER_RENDERMODE_WHEN_DIRTY:
        ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        break;

    case ApplicationInterface.MSG_PROCESSING_BLOCK_UI:
        ApplicationScreen.getGUIManager().processingBlockUI();
        break;

    case ApplicationInterface.MSG_BROADCAST:
        pluginManager.onBroadcast(msg.arg1, msg.arg2);
        break;
    default:
        break;
    }

    return true;
}

From source file:org.kontalk.ui.ComposeMessageFragment.java

/** Starts an activity for shooting a picture. */
private void selectPhotoAttachment() {
    try {/*from w  w w . ja v  a  2  s  .  c om*/
        // check if camera is available
        final PackageManager packageManager = getActivity().getPackageManager();
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() <= 0)
            throw new UnsupportedOperationException();

        mCurrentPhoto = MediaStorage.getOutgoingImageFile();
        Uri uri = Uri.fromFile(mCurrentPhoto);
        Intent take = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        take.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri));
        }

        startActivityForResult(take, SELECT_ATTACHMENT_PHOTO);
    } catch (UnsupportedOperationException ue) {
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Log.e(TAG, "error creating temp file", e);
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show();
    }
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.TlcInsurance.java

private void cameraIntent() {
    if (btnClicked == licenseButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_LICENSE);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_LICENSE);

    } else if (btnClicked == ssCardButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SSCARD);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SSCARD);
    } else if (btnClicked == baseLetterButton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_BASELETTER);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_BASELETTER);
    } else if (btnClicked == utilityBillsbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_UTILITYBILLS);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_UTILITYBILLS);
    } else if (btnClicked == mvTitlebutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_MVTITLE);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_MVTITLE);
    } else if (btnClicked == sixhrdrivingbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_sixhrdriving);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_sixhrdriving);
    } else if (btnClicked == shlPermitbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SHLPERMIT);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SHLPERMIT);
    } else if (btnClicked == shlpermitreceiptbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_SHLRECEIPT);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_SHLRECEIPT);
    } else if (btnClicked == ispermitownedbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_ISPERMITOWNED);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_ISPERMITOWNED);
    } else if (btnClicked == certificatebutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_certificate);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_certificate);
    } else if (btnClicked == fillingbutton) {
        //            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //            startActivityForResult(intent, REQUEST_CAMERA_filling);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "New Picture");
        values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, REQUEST_CAMERA_filling);
    }/*from w  ww .ja  va2  s . c  o  m*/
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private void takePhoto() {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        final File cache_dir = getExternalCacheDir();
        final File file = new File(cache_dir, "tmp_photo_" + System.currentTimeMillis());
        mTempPhotoUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mTempPhotoUri);
        try {/*w ww.  j av a  2s. co  m*/
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        } catch (final ActivityNotFoundException e) {
            showErrorMessage(this, null, e, false);
        }
    }
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * ?//  w  w w . j  a v a  2  s .  c  o m
 */
public void selectPicFromCamera() {
    if (!CommonUtils.isExitsSdcard()) {
        MyToast.makeText(getApplicationContext(), "SD????", 0).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(),
            LiuLianApplication.current_user.getHx_username() + System.currentTimeMillis() + ".jpg");
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA);
}

From source file:com.keylesspalace.tusky.ComposeActivity.java

private void initiateCameraApp() {
    addMediaBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    // We don't need to ask for permission in this case, because the used calls require
    // android.permission.WRITE_EXTERNAL_STORAGE only on SDKs *older* than Kitkat, which was
    // way before permission dialogues have been introduced.
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;//  ww w  .ja  v a  2 s .c o m
        try {
            photoFile = createNewImageFile();
        } catch (IOException ex) {
            displayTransientError(R.string.error_media_upload_opening);
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            photoUploadUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider",
                    photoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUploadUri);
            startActivityForResult(intent, MEDIA_TAKE_PHOTO_RESULT);
        }
    }
}

From source file:org.wheelmap.android.fragment.POIDetailFragment.java

private void startPickPhotoDialog() {

    // user must be logged in
    UserCredentials credentials = new UserCredentials(getActivity());
    if (!credentials.isLoggedIn()) {
        Intent intent = new Intent(getActivity(), ProfileActivity.class);
        startActivityForResult(intent, REQUEST_CODE_LOGIN);
        return;//  www  . j  av a2  s  .  c o m
    }

    final Item[] items = {
            new Item(getString(R.string.photo_upload_picker_gallery), android.R.drawable.ic_menu_gallery),
            new Item(getString(R.string.photo_upload_picker_take_new), android.R.drawable.ic_menu_camera) };

    final ListAdapter adapter = new ArrayAdapter<Item>(this.getActivity(), android.R.layout.select_dialog_item,
            android.R.id.text1, items) {
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);

            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp5);

            return v;
        }

    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

    builder.setTitle(R.string.photo_upload_picker_title);
    builder.setCancelable(true);

    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                startGetPhotoFromGalleryIntent();
            } else if (which == 1) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                new_photo_file = new File(Environment.getExternalStorageDirectory() + "/DCIM/",
                        "image" + new Date().getTime() + ".png");
                Uri pictureURI = Uri.fromFile(new_photo_file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureURI);
                startActivityForResult(intent, Request.REQUESTCODE_PHOTO_FROM_CAMERA);
            }

        }
    });
    dialog = builder.create();
    dialog.show();

}