Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fileName from uri?

I got some uri, that looks something like this content://media/internal/audio/media/48 I got it from intent, but I want to get the file name of the file it point to. How can I do this ?

like image 417
Lukap Avatar asked Jun 29 '11 10:06

Lukap


2 Answers

I found the solution

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

and than the name is taken like this

r.getTitle(this));
like image 140
Lukap Avatar answered Sep 24 '22 19:09

Lukap


If I understood you right, I would try create a new File object with File aFile = new File(uri) and then call getName() on aFile.

edit: or try it like this:

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

list() would give you a stringarray of the contained files...

like image 24
Tobi N Avatar answered Sep 20 '22 19:09

Tobi N