如何检查蜂窝或更高的运行,并据此要求该版本的方法? [英] How do I check HoneyComb or higher is running, and accordingly call a method for that Version?
问题描述
有关的Android版本3.0和更高版本,我想打电话给一定的方法。 有没有一种方法来检查,如果在运行Android版本一定的方法可用?
要更precise,我MinSDK为7(Android 2.1的),TargetSDK是8(安卓2.2),我需要测试 如果蜂窝的Android 3.0或更高版本上运行。 根据这一点,我怎么能称之为蜂巢的方法?
问题的第二部分出现了,因为只调用该蜂窝方法,将无法编译,因为我对建设2.2。
要更precise,我MinSDK为7(Android 2.1的),TargetSDK是8(安卓2.2),我需要测试是否蜂窝的Android 3.0或更高版本上运行。根据这一点,我怎么能称之为蜂巢的方法?
步骤1:将您的构建目标,你要直接调用,因此对编译的最高API级别。您的构建目标(例如,项目>属性> Android的)是不是与你的机器人:targetSdkVersion
步骤#2:由于其他答案均表示,可以再有条件地调用保护块中的方法:
如果(android.os.Build.VERSION.SDK_INT> = android.os.Build.VERSION_ codeS.HONEYCOMB){
//调用东西API等级11+
}
问题的第二部分出现了,因为只调用该蜂窝方法,将无法编译,因为我对建设2.2。
您需要更改您的构建目标是API级别11或者,如果你想直接调用API级别11或更高的方法高。
For Android Versions 3.0 and higher, I want to call a certain method. Is there a way to check if a certain method is available in the running Android Version?
To be more precise, my MinSDK is 7 (Android 2.1), TargetSDK is 8 (Android 2.2) and I need to test if HoneyComb Android 3.0 or higher is running. Depending on that, how can I call that HoneyComb method?
The second part of the question arises, because simply calling that HoneyComb method, will not compile, as I am building against 2.2.
To be more precise, my MinSDK is 7 (Android 2.1), TargetSDK is 8 (Android 2.2) and I need to test if HoneyComb Android 3.0 or higher is running. Depending on that, how can I call that HoneyComb method?
Step #1: Set your build target to the highest API level you wish to call directly and therefore compile against. Your build target (e.g., Project > Properties > Android) is not related to your android:targetSdkVersion
.
Step #2: As the other answers have indicated, you can then conditionally call methods within a guard block:
if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB) {
// call something for API Level 11+
}
The second part of the question arises, because simply calling that HoneyComb method, will not compile, as I am building against 2.2.
You need to change your build target to be API Level 11 or higher if you wish to directly call API Level 11 or higher methods.
这篇关于如何检查蜂窝或更高的运行,并据此要求该版本的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!