How to get file name from uri?

I have some uri that looks something like this Contents: // media / internal / audio / media / 48 I got this from the intention, but I want to get the file name of the file that it points to. How can i do this?

+4
source share
3 answers

I found a solution

Ringtone r=RingtoneManager.getRingtone(this, uri); 

and the name is taken as

 r.getTitle(this)); 
+3
source

If I understood what was right, I will try to create a new File object with the file aFile = new File (uri), and then call getName () on aFile.

edit: or try to do it like this:

 File aFile = new File(uri); if(aFile.isDirectory()) { aFile.list() } else { aFile.getName() } 

list () will provide you with a string file of the contained files ...

+4
source

Here is the code ...

 File objFile = new File(File_Path); objFile.getName(); 
+1
source

All Articles