I want to check size of file where I have only URI content://media/external/video/media/813
to get size of file I use:
File file=new File(uri.getPath());
long ls = file.length();
and always get 0. Any ideas?
Try below code to get length of your file
Cursor returnCursor =
getContentResolver().query(uri, null, null, null, null);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
int size = (int) returnCursor.getLong(sizeIndex);
try this,
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
File file = new File(filePath);
long ls = file.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