1

How do you detect what kind of file the resource is? In my case there could be videos and images.

So in case it's a video, I use a VideoView; and in the case of an image, I use an ImageView?

I'm getting the resource id like this:

AssetFileDescriptor afd = context.getResources().openRawResourceFd(resourceID); 

2 Answers 2

1

I think it's impossible without reading/ analyzing the binary data of files (like TrID). The easiest way is to prefix file names with predefined strings. For example:

  • video_file_00, video_file_01
  • image_file_00, image_file_01

Then you can use getResourceName(int) to parse the file names.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is the most simple way. Thanks, this will work the best I think
1

the only thing I have in mind is that you can check the file names using constants like this:

 final String type = getApplicationContext().getResources().getResourceTypeName(resID); if(type.equals("drawable")){ // handle it like an image }else if(.....) //do some research for other constants 

1 Comment

How would I get the filename? Im just have the resource id

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.