Show Image View from file path?
Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder ,
This kind of path is needed only when your images are stored in SD-Card .
And try the below code to set Bitmap images from a file stored inside a SD-Card .
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
myImage.setImageBitmap(myBitmap);
}
And include this permission in the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Is it possible to set image to ImageView from a path (external storage) on Android 10 and higher?
Yes it is possible. first add this line to the application manifest
android:requestLegacyExternalStorage="true"
in your gradle file set this options(if its not)
compileSdkVersion 29
and after obtaining permission to use access to memory - you can upload a picture
How to set an image to imageView using filepath in android
If with File
you mean a File
object, I would try:
File file = ....
Uri uri = Uri.fromFile(file);
imageView.setImageURI(uri);
How to set image path on image view in android
I think you are going to work with JSON,
And load image from server,
If yes than I will suggest you to use any image loader like universal-image loader.
Universal image loader
Android Studio getting image view file path / uri
Hey there this is how i do it, have a try
private void uploadInputStream() {
Uri path = Uri.parse("com.example.project/" + R.id.ivProfilePicture);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
InputStream exampleInputStream = null;
File file = null;
try {
exampleInputStream =
getContentResolver().openInputStream(Uri.parse(bitmap));
file = new File(String.valueOf(inputStream)); //upload the file
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Let me know how it goes
Can not load image from file path to ImageView with Glide
Just need to add android:requestLegacyExternalStorage="true"
to Application
tag in Manifest.xml
.
Related Topics
How to Get Pixel Color in Android
Android - Sms Broadcast Receiver
How to Check Grants Permissions At Run-Time
Android Drawing Separator/Divider Line in Layout
How to Install an Apk File in the Android Emulator
Separate Back Stack For Each Tab in Android Using Fragments
How to Detect When an Android Application Is Running in the Emulator
Need to Handle Uncaught Exception and Send Log File
How to Get the Absolute Coordinates of a View
Android: How to Check If a View Inside of Scrollview Is Visible
Recyclerview and Handling Different Type of Row Inflation
How to Add Manifest Permission to an Application
Change Volley Timeout Duration
Self-Signed Ssl Acceptance on Android