Extending platform scope
The support libraries we have been working with throughout the book do a marvelous job of making our apps available on older devices, but they do not work for all situations, and many new innovations simply cannot be realized on some older machines. Taking a look at the following device dashboard, it is obvious that we would like to extend our apps back to API level 16:
We have seen how the AppCompat library enables our apps to run on platforms even older than this, but we have to avoid using some features. For example, the view.setElevation()
method (along with other material features) will not work below API level 21 and will cause the machine to crash if it is called.
It would be tempting to think that we could simply sacrifice such features for the benefit of reaching a wider audience, but fortunately, this is not necessary as it is possible to detect dynamically which platform our app is running on with the following conditional clause:
if (Build.VERSION.SDK_INT...