Higher API calls when lower SDK targeted

后端 未结 3 749
既然无缘
既然无缘 2020-12-17 18:23

My app supports minSdkVersion=10 and targeting 16. I want to call methods specific to API level >= 14 if a specific device supports them. I could check running OS version at

相关标签:
3条回答
  • 2020-12-17 18:34

    You can test the device's API with this:

    if(android.os.Build.VERSION.SDK_INT >= 14) {
        // Do something fancy
    }
    else {
        // Do something regular
    }
    
    0 讨论(0)
  • 2020-12-17 18:41

    In addition of checking the current version you should also add @SuppressLint("NewApi")to your method so the compiler want yell about it.

    0 讨论(0)
  • 2020-12-17 18:54

    Methods from higher API are invisible and inaccessible because project's target SDK is lower than SDK which methods are going to be used. For example: if you want to use methods from API 14 Android project target SDK should be at least 14 or even better the latest (currently 16). That is kind of obvious but I missed it. After that the solution Sam gave a reference to is in use.

    0 讨论(0)
提交回复
热议问题