Have edited my question to make it more clear.
Basically I am working on an App where users need to upload their profile image. However I need to limit the size of the image upload to less than 4MB. Here where user selects his image from the image gallery, at that very instant I need to check the image file's size and show an alert to the user if the file size is greater than 4MB and restrict the upload.
Presently I am using this code to get the file size:
File Img = new File(selectedImage.getPath()); int length = Img.length();
I know length() returns file size in bytes, however even after conversion from bytes to MB, this always seems to return very small values than the original image file size leading to me believe that getting the file size this way is inaccurate.
Is there any other way I can get the file size of the image files from the device gallery?
Any help is much appreciated. Thanks guys.