Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the size of an Android file resource?

Tags:

I have a video file in the raw folder in my resources. I want to find the size of the file. I have this piece of code:

Uri filePath = Uri.parse("android.resource://com.android.FileTransfer/" + R.raw.video);                 File videoFile = new File(filePath.getPath());                 Log.v("LOG", "FILE SIZE "+videoFile.length()); 

But it always gives me that the size is 0. What am I doing wrong?

like image 663
Alex1987 Avatar asked May 18 '11 19:05

Alex1987


People also ask

How do I find file size on android?

file. length() returns the length of the file in bytes, as described in the Java 7 Documentation: Returns the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist.

What is dimension resource in Android?

Note: A dimension is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine dimension resources with other simple resources in the one XML file, under one <resources> element. The filename is arbitrary.

What is resource value in Android Studio?

Resources are used for anything from defining colors, images, layouts, menus, and string values. The value of this is that nothing is hardcoded. Everything is defined in these resource files and then can be referenced within your application's code.

What is a resource file in Android?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.


1 Answers

Try this:

AssetFileDescriptor sampleFD = getResources().openRawResourceFd(R.raw.video); long size = sampleFD.getLength() 
like image 195
shem Avatar answered Sep 20 '22 22:09

shem