0

I am trying to take photo and save it to external storage, then i save path of photo to load this photo for using profile image.

public void capture()
        {
            Intent intent = new Intent();
            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File f = getExternalFilesDir(Environment.DIRECTORY_PICTURES);




            file = new File(f, "img_" + timeStamp+".jpg");

            photoUri = FileProvider.getUriForFile(EditProfileActivity.this,
                    BuildConfig.APPLICATION_ID + ".provider",
                    file);

            intent.putExtra("data", photoUri);
            //Log.i("Pathfewffewf",file.getPath());
            startActivityForResult(intent,0);
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == 0 && resultCode == RESULT_OK) {

                if (data != null) {


                    Bitmap photo = (Bitmap) data.getExtras().get("data");
                    Bitmap circleBitmap = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.ARGB_8888);

                    BitmapShader shader = new BitmapShader(photo, TileMode.CLAMP, TileMode.CLAMP);
                    Paint paint = new Paint();
                    paint.setShader(shader);
                    paint.setAntiAlias(true);
                    Canvas c = new Canvas(circleBitmap);
                    c.drawCircle(photo.getWidth() / 2, photo.getHeight() / 2, photo.getWidth() / 2, paint);
                    imageView.setImageBitmap(circleBitmap);




                }
            }

Then I have

            Bitmap myBitmap = BitmapFactory.decodeFile(user.getmImage());



            image.setImageBitmap(myBitmap);

I put Log Message When it saves Image and When it load Image but

04-25 01:24:40.869 24049-24049/assignment.csc214.project3 I/Pathfewffewf: /storage/emulated/0/Android/data/assignment.csc214.project3/files/Pictures/img_20180425_012440.jpg
04-25 01:24:40.984 24049-24065/assignment.csc214.project3 D/EGL_emulation: eglMakeCurrent: 0xa37f4b80: ver 2 0 (tinfo 0xa3794840)
04-25 01:24:44.146 24049-24049/assignment.csc214.project3 E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Android/data/assignment.csc214.project3/files/Pictures/img_20180425_012440.jpg (No such file or directory)

It has same path, but it says there is no such file or directory...... I think file is not save properly what should i do

Scott Kim
  • 233
  • 1
  • 4
  • 13
  • Possible duplicate of [Android: Taking photo and saving that image in internal/external storage with specific name by programmatically?](https://stackoverflow.com/questions/38842087/android-taking-photo-and-saving-that-image-in-internal-external-storage-with-sp) – Somesh Kumar Apr 25 '18 at 05:38
  • 1
    You want to put the `photoUri` extra on the `Intent` with `MediaStore.EXTRA_OUTPUT` as the key, not `"data"`. That is, `intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);`. – Mike M. Apr 25 '18 at 05:43
  • follow this [answer](https://stackoverflow.com/questions/49685461/fileprovider-is-very-confusing/49685978#49685978) – Mohammed Farhan Apr 25 '18 at 05:50

0 Answers0