I am working on an app that uses a custom file type, I’ve figured out how to register my app with the system as being able to open files of this type using intent filters and my app will also show up on the list of apps that can be used to open this file from the built in email client when trying to open an attachment of this type. The problem is the code that handles opening the file when passed in from the file browser does not work when it is passed in from the email client. Here is the code that I use that works correctly when the Activity is called from the file browser after selecting a file of the correct type:
Intent i = getIntent();
if(i == null) return;
Uri u = i.getData();
if(u == null) return;
String filePath = u.getEncodedPath();
if(filePath == null) return;
Util.loadOTDRFile(filePath);
What I get in the “filePath” string when loading from the file browser is something like “mnt/storage/Android/data/com.fiberdroid.001/downloads/filename.trc… and that works fine my app loads it in the loadOTDRFile() function successfully.
However, when I open the same type of file from the email client the filePath variable in that code ends up being something like the following: “//mail/parts/4217” which does not load, my load function returns a file not found error.
Here is the relevant code from the loadOTDRFile() function:
File file = new File(filePath);
InputStream is;
try
{
is = new FileInputStream(filePath);
}
catch(FileNotFoundException e)
{
return D.ERROR_FILENOTFOUND;
}
I guess my question is what kind of path is “//mail/parts/4217” and why can’t I open it?
Thank you.
That’s a Content URI… You’ll need to use ContentResolver to open the file from the mail provider.
To do that you should do:
You may wish to put something like this: