Get Content Uri from File Path in Android

Get content uri from file path in android

Try with:

ImageView.setImageURI(Uri.fromFile(new File("/sdcard/cats.jpg")));

Or with:

ImageView.setImageURI(Uri.parse(new File("/sdcard/cats.jpg").toString()));

Get Uri from File or FilePath

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

Convert a file path to Uri in Android

Please try the following code

Uri.fromFile(new File("/sdcard/sample.jpg"))

How to get the Full file path from URI

Use:

String path = yourAndroidURI.uri.getPath() // "/mnt/sdcard/FileName.mp3"
File file = new File(new URI(path));

or

String path = yourAndroidURI.uri.toString() // "file:///mnt/sdcard/FileName.mp3"
File file = new File(new URI(path));


Related Topics



Leave a reply



Submit