I’ve added the Google MAPs API to my app, but it’s not a critical part. I would like my app to run on systems which are missing this library, but avoid getting an exception when the user tries to access the map function. I’ve tried putting try/catch blocks around my activity, but it doesn’t seem to be able to catch the missing library exception. Is there any way to detect that the maps library is missing before starting my map activity?
Update: The reason I asked this question is because I bought the MK802 Android mini PC and I believe this device will be popular. It ships with Android 4.0, however it is missing the map api library. I would like my app to be available to install on the device. Currently, my app runs fine, but crashes when the user tries to access the map function (not very important feature). I suppose I can live with this, but it would be best to avoid getting the exception if possible.
Google provided an article on how to do this between Android versions. ie, How do I access an api in a particular version of Android but fail gracefully if it’s not there in another version of Android. The same premise could be used here for your map portions of the code.
http://developer.android.com/resources/articles/backward-compatibility.html
The bottom line is that you are using reflection to accomplish this.
The reason to use reflection is because if your activity imports another Class but that class does not exist, then the Activity will not be able to be created. Using Reflection solves this, since you’ll be able to try/catch the class instantiation.