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
Bad Class File Magic or Version
Android Popup Window Dismissal
How to Determine Device Screen Size Category (Small, Normal, Large, Xlarge) Using Code
Android Spinner with Multiple Choice
How to Put Multiple Project_Number/Sender Id in Google-Services.JSON
How to Implement Multi-Select in Recyclerview
Locationclient Getlastlocation() Return Null
Google Play Services Library Update and Missing Symbol @Integer/Google_Play_Services_Version
How to Use the Simple Http Client in Android
How to Set Tint for an Image View Programmatically in Android
Passing Arraylist of Objects Between Activities
Retrieve Incoming Call's Phone Number in Android
Border for an Image View in Android
How to Capture the Android Device Screen Content
Recommended Way/Order to Read Data from a Webservice, Parse That Data and Insert It in a SQLite Db
How to Connect Android App to MySQL Database
Google Sign in Failed Com.Google.Android.Gms.Common.Api.Apiexception: 10:
How to Display Inline Images from HTML in an Android Textview