alacoo
alacoo

Reputation: 145

Get Uri from File or FilePath

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);
        }
    }

Upvotes: 2

Views: 11989

Answers (2)

alacoo
alacoo

Reputation: 145

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);
        }
    }

Upvotes: 1

Saurabh Mistry
Saurabh Mistry

Reputation: 13669

Try this :

Uri.fromFile(new File("/storage/emulated/0/iWallet/photos/JPEG_20180119040510_972640968.jpg"))

Upvotes: 4

Related Questions