android system camera returns picture (original)

Posted by pharcyde0 on Mon, 20 Jul 2020 16:29:32 +0200


 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.CAMERA"></uses-permission>

Jump to Camera

    private void  intent_Carmer(){
        String state = Environment.getExternalStorageState();
//        Get SD card status
        if (state.equals(Environment.MEDIA_MOUNTED)) {
//            If SD card exists and is readable and writable
            File file = new File(path);
//             Create a new folder here.Path Save path for picture
            if (!file.exists()) {
//                If the file does not exist
//                new file
        String fileName = getPhotoFileName() + ".jpg";
//        Picture name, time here
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//        MediaStore.ACTION_IMAGE_CAPTURE for Jump to Camera
        path_carmer =path + fileName;
//        path_carmer as String Global Variable"Picture Final Path
           Uri uri     = Uri.fromFile(new File(path_carmer));
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
//        Match your own picture save address
//        Start Jump


getPhotoFileName() returns the picture name (name here is time)

 private String getPhotoFileName() {
        Date date = new Date(System.currentTimeMillis());
        //System.currentTimeMillis()-----) Time
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");

        return "IMG_" + dateFormat.format(date);

path_carmer global string variable

private String path_carmer;//Camera Picture Final Storage Path

path Picture Save path (DCIM folder appears in this album)

    private String path = Environment.getExternalStorageDirectory()
         + File.separator + Environment.DIRECTORY_DCIM + File.separator;

TAKE_PHOTO Identifies Request

private static final int TAKE_PHOTO=1222;

After completing these steps, you are faced with an imageView display picture when the camera point is determined

  case TAKE_PHOTO:
                    FileInputStream fis = null;
                    try {
                        fis=new FileInputStream(path_carmer);
                        Bitmap bitmap=BitmapFactory.decodeStream(fis);
                    } catch (FileNotFoundException e) {
                    }finally {
                        try {
                        } catch (IOException e) {

Displaying pictures must be in the OnActivityResult () method, which is overridden with three parameters

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //requestCode request identification; resultCode result identification; data data data
        super.onActivityResult(requestCode, resultCode, data);

case is where I use switch to determine requestCode.


The picture is shown here at my address, so the data is empty

File operation to catch exceptions

Dynamic Load Rights if Mobile Phone is ANDROID 6.0 or above

Topics: Android Mobile