I am looking for a way to check if I can discover a specific intention. I know how to check if an action is available, for example in this example . However, this is not as good as an action such as Intent.ACTION_VIEW can open different applications depending on the uri presented.
Point in case:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url);
startActivity(i);
This will open another application for different URLs, for example:
url = "ftp://192.168.1.1"
url = "http://192.168.1.1"
The http url is pretty safe: it will open in your browser by default. The ftp url is wrong because it is not sure that users have an ftp client installed (for my case, I assume AndFTP as a client, since it seems to be one of the most popular clients, and there is no standard way to send un / pw to the client, so this should be application specific).
So now I want to check not only if the action is available (the linked code will return true if http is available, but ftp is not), but also if there is an application that can handle a certain sort. Testing for a specific application would also be acceptable.
And finally, this should be included in the code snippet that selects one or more URIs that should open the first possible, and return an error code if no URIs can be opened. Something like this pseudo code:
success = false;
for (Uri uri : uris) {
if (actionAvailable(uri)) {
// set up intent
startActivity(intent);
success = true;
break;
}
}
return success;
source
share