Вопрос

My Question: Can I support an older api and use functions of a newer api if available?

My Situation: I'm building a simple app that I want to support some advanced functions with the UI if available. But the API level I'm supporting is 13 so I can support Android 3.2. Specifically, I want to use the View.SYSTEM_UI_FLAG_* variables, but those are not available in api level 13.

Это было полезно?

Решение

Yes, you can check that at runtime:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   // my code using HC API
} else {
   // code that works on older API
}

and you have to set android:targetSdkVersion of your app's Manifest to highest API version you want to support, otherwise you will not be able to build it.

Please see this <uses-sdk> related article.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top