Chris Simpson Chris Simpson - 6 months ago 17
Android Question

How do I determine whether a path is a local file or not

Given just a location as a string, is there a reliable way to determine if this is a local file (such as /mnt/sdcard/test.jpg) or a remote resource (such as http://www.xyz.com/test.jpg)?

Converting it to a Uri with Uri.parse doesn't seem to give me anything to indicate where the file is.

I don't really want to have to look for // in the string!

Answer

uri format is

<protocol>://<server:port>/<path>

local files have:

file:///mnt/...

or just

 /mnt

so if string starts with

\w+?://

and this is not file:// then this is url