Search code examples
androidandroid-mediaplayerlockscreenwidget

Android Multiple API Integration


I need to know how to build an Android app targeting android:minSdkVersion="8" but also include features available in Latest Android API's as well. So when a user runs the app on FROYO basic functionalities will work. But the same app runs on KITKAT more functionalities will appear.

PS: I'm developing a an app for a radio station, where an online stream gets played. But I want to integrate lock screen access of the media controls (Play, Pause buttons) and it only available on Android 4.2 (API 17). My app's min SDK is 8.

So I'm asking is how to write code belongs to different API's? Or any other alternatives also welcome. Thanks in advance.


Solution

  • You can use the Version codes to decide wheather to execute a part of code or not.

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
        // only for gingerbread and newer versions
    }
    

    For the lock screen thing, i guess you do execute the code only it supports. Since the support is not there its obvious that other apps running on them will not have them. Try resorting to some other methods :-/