This will give me a file path like this: /storage/emulated/0/myimage.jpg
File imageFile = File(Environment.getExternalStorageDirectory(), "myimage.jpg");
String path = destination.getAbsolutePath();
Log.d("path", path);
If I use this path to load the image into an ImageView using Picasso, it won't work.
Picasso.with(this.context).load("/storage/emulated/0/myimage.jpg").into(imageView);
It works only if I prefix the path with file://
Picasso.with(this.context).load("file:///storage/emulated/0/myimage.jpg").into(imageView);
Is there a way to get the file path with this file:// instead of getting the absolute path and then prepend this manually?
You need to use Uri.fromFile to get URI from file:
Uri uriFileName = Uri.fromFile(yourFile);
String uriStr = uriFileName.toString();
Example: "file:///tmp/android.txt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With