Is there a way to check and see if an Activity exists on your device? If I have a youtube video link I want to specify it open in the YouTube PlayerActivity. However, I don't want to crash if for some reason they don't have it.
Is there a way to check and see if the activity exists? I don't think I can catch the runtime exception since startActivity() doesn't throw it.
I ended up doing:
This ensures that the google-specific Add Account intent exists, and if not, falls back on the general more general ACTION_ADD_ACCOUNTS.
Actually, this works:
This is the simplest way to do this:
It is also the one recommended by Google:
Here's how I check if an
Activity
is available on the device:You could create an Intent object with necessary component info and then check if the intent is callable or not.I stumbled upon this snippet here on SO, don't have the link to the actual thread.