简体   繁体   English

目标KitKat MR2(4.4.3)?

[英]Target KitKat MR2 (4.4.3)?

I have a piece of code (actually a library I'm including) that only functions correctly using KitKat MR2 (4.4.3). 我有一段代码(实际上是我包括的一个库),只能使用KitKat MR2(4.4.3)正常运行。

The other MR seem to have to their own API versions in Build.VERSION_CODES, but I can't find any way to target 4.4.3 and above using the SDK_INT. 其他MR在Build.VERSION_CODES中似乎具有其自己的API版本,但是我找不到使用SDK_INT定位到4.4.3及更高版本的任何方法。 Should I just use the incremental String field and do a String comparison? 我应该只使用增量String字段并进行String比较吗?

// the "easy" (wrong) way
if(Build.VERSION.SDK_INT >= BUILD.VERSION_CODES.KIT_KAT) { // but that includes 4.4, 4.4.1, and 4.4.2!

}

// the "hard" way
if(compareVersionCodes(BUILD.VERSION.RELEASE, "4.4.3") > 0) { // implement some comparison function for the version codes instead

}

Is targeting KIT_KAT acceptable -- meaning is this something like version 14 vs 15 where everyone automatically gets the higher version? 是否可以接受以KIT_KAT为目标的目标-就是说像版本14与版本15这样,每个人都会自动获得较高版本吗?

I can't find any way to target 4.4.3 and above using the SDK_INT 我找不到使用SDK_INT定位到4.4.3及更高版本的任何方法

The API levels are for changes in binary compatibility -- stuff like new classes, new methods, etc. They aren't for bug fixes, other than to the extent such fixes break binary compatibility. API级别用于更改二进制兼容性-诸如新类,新方法等之类的内容。它们不用于错误修复,除非此类修复破坏了二进制兼容性。

Should I just use the incremental String field and do a String comparison? 我应该只使用增量String字段并进行String比较吗?

That's not awesome, but unless there's some way you can interrogate the Bluetooth LE APIs to see whether or not you're on a malfunctioning device, you may need to go this route. 那并不好,但是除非有某种方法可以询问Bluetooth LE API以查看您是否在故障设备上,否则您可能需要走这条路。 However, later this year, I'd set up the check algorithm to be more like: 但是,今年晚些时候,我将设置检查算法,使其更像是:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.WHATEVER_THEY_CALL_L ||
  (Build.VERSION.SDK_INT == Build.VERSION_CODES.KIT_KAT && getPatchLevel()>=3)) {
     // do your thing
}

where getPatchLevel() tries to use RELEASE to find the patch level and fails gracefully if RELEASE is not of the form XYZ This approach will handle both the 4.4.3/4.4.4 scenarios and whatever the numbering is for the next Android version. 如果getPatchLevel()尝试使用RELEASE查找补丁程序级别,并且如果RELEASE的格式不是XYZ,则该方法会优雅地失败。此方法将处理4.4.3 / 4.4.4场景以及下一个Android版本的编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM