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?

Answer

Use getIdentifier()

int resourceId = this.getResources().getIdentifier("file_name", "raw", this.getPackageName());


Source: stackoverflow