1

I have file in this path:

file:/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg

I want to convert it to android.net.Uri and use it in this:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoFile.toURI());
            startActivityForResult(takePictureIntent, REQUEST_TAKE_CAMIRA);
        }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
alacoo
  • 135
  • 1
  • 1
  • 6
  • "i have file in this path "file:/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg"" -- that is not a path. `/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg` is a path. On Android 7.0 and older, you can get away with using `Uri.fromFile()`. On newer devices, use `FileProvider` to serve up files from this location. – CommonsWare Jan 19 '18 at 01:10
  • 1
    Check out this https://stackoverflow.com/questions/42460710/how-to-convert-a-bitmap-image-to-uri – Gerardo Soriano Jan 19 '18 at 01:21
  • thanks @CommonsWare for your fast answer i selvet by check my FileProvider xml path – alacoo Jan 19 '18 at 01:26

2 Answers2

3

Try this :

Uri.fromFile(new File("/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg"))
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71
1

my problem was with File Provider so i solve like that

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {

        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(context,
                    DBConnect.FILEPROVIDER,
                    photoFile);

            URI uri = photoFile.toURI();


            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_CAMIRA);
        }
    }
alacoo
  • 135
  • 1
  • 1
  • 6