Android: how to code depending on the version of the API?

后端 未结 2 1414
滥情空心
滥情空心 2020-12-17 21:19

In Android I get the version of the SDK easily (Build.VERSION.SDK) but I need to use LabeledIntent only if the platform is newer than 1.6 (>Build.VERSION_

相关标签:
2条回答
  • 2020-12-17 22:09

    Follow the wrapper class pattern documented in the page you linked to above.

    0 讨论(0)
  • 2020-12-17 22:21

    You have to use reflection... The idea is good, but in your code you refer to LabeledIntent which is not available in 1.6. So when your app runs against 1.6 devices, it cannot find the class and crashes.

    So the idea is to write code where you don't refer to LabeledIntent when running in 1.6. To do this, you can write a wrapper class (LabeledIntentWrapper) which extends LabeledIntent and call it in your function. So, in 1.6, the device will see a reference to a known class: LabeledIntentWrapper.

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