-1

I am using Android Intent Chooser to select a photo from gallery with following code.

ivAvatar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Bir fotoğraf seçin ..."), 1);
        }
    });

After selection using the path I fill the imageview with following code :

Uri selectedImageUri = data.getData();

        imagepath = ImagePathUtil.getPath(getApplicationContext(), selectedImageUri);
        Bitmap bitmap = BitmapFactory.decodeFile(imagepath);
        ivAvatar.setImageBitmap(bitmap);

        selectedU = selectedImageUri;

        File f = new File(String.valueOf(selectedU));

        if(f.exists())
        {
            int i = 1;

        }

Image can be viewed without any problems, but the File object I create afterwards File 's exists() method always return false.

onder
  • 795
  • 3
  • 14
  • 32

1 Answers1

1

It is returning false because the file will be null. Please look at the below post for more details on how to get the real path from URI.

URI from Intent.ACTION_GET_CONTENT into File

Community
  • 1
  • 1