Possible Duplicate:
Android: Get the size of a file in resources?
I want to upload a file to a WebServer. To show the progress of the upload I need to know the complete size of the file. Since I have only the Uri of the file (got it from an Intent), I have no chance to get at the file's size. My workaround is to open an InputStream and count the bytes that are read on this InputStream. But this is circuitous. Is there an easier/conventional way to solve this issue?
Thanks
2. How To Get The Real File Path From Android URI. At some time, only save the image URI in the android app is not enough, because the image URI may be changed, or the image URI is not changed but its related image may be removed. In this case, we need to save the URI-related images in the android app folder.
If the URI is a Images.Media.EXTERNAL_CONTENT_URI (e.g. from Intent.ACTION_PICK for the Gallery) from you will need to look it up as in stackoverflow.com/q/6935497/42619 @Chlebta check out a library called Picasso for loading Files (even URLs) into ImageViews very easily.
At some time, only save the image URI in the android app is not enough, because the image URI may be changed, or the image URI is not changed but its related image may be removed.
Because from android SDK version 19, to make Android apps secure, android does not allow one Android app to access other app-created files from the android storage system directly. If your Android app wants to access other app-created files, you should get the file from its ContentProvider with a content URI.
You can get the size of the file in bytes thus:
File f = new File(uri.getPath()); long size = f.length();
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