Skip to content
Advertisement

Android studio get file path by name

I want to get the full address by the name of the file. For example:

Input young_volcanos – String name

Output R.raw.young_volcanos – int path

Is it possible?

Advertisement

Answer

Use getIdentifier()

int resourceId = this.getResources().getIdentifier("file_name", "raw", this.getPackageName());
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement