0

My current project has minSDK 14 and I am trying to integrate the caption sytle provided by Android's device accessibility settings.

The API that I want to integrate was introduced only from API level 19.

CaptioningManager.CaptionStyle

Is there a way I can use the API without changing the minSDK?

Raghav
  • 1,014
  • 2
  • 16
  • 34

1 Answers1

0

You can set up a way to implement your captioning only if the SDK supports it.

i.e., If something I wanted was introduced in Lollipop, I could use this code to make the captioning enabled.

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
    // Do something for lollipop and above versions
} else{
    // do something for phones running an SDK before lollipop
}

I don't believe that you are going to get captioning in an earlier release than 19 if that is where it was introduced.

Hope this helps!

Borrowed snippet from this answer here: Retrieving Android API version programmatically

Community
  • 1
  • 1
Alexander N.
  • 1,458
  • 14
  • 25
  • Wont the compiler complain if you are trying to use an API feature that is present in future version? In your case, if your minSDK is Kitkat and if you are trying to run Lollipop API, it will result in compiler error. – Raghav Mar 22 '16 at 17:05
  • No, it will only complain if you are trying to use it in your regular code without checking for the API version. If your minSDK is kitkat and you are checking for a feature that is available within lollipop and your targetSDK is marshmellow, you should be fine. – Alexander N. Mar 22 '16 at 18:10
  • That is, if you are putting your logic to use captioning inside the braces here: `if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){ // Do something for lollipop and above versions}` you should be fine. If the item you are trying to use exists outside of these braces, you will have issues. Additionally, if the target SDK is not higher than what you are trying to use, you will have issues. minSDK is the minimum that is required by your app to run. It will not have the features that are in newer SDKs if they don't exist in that version or in a support library. – Alexander N. Mar 22 '16 at 18:26