端末のOSのバージョンをみる.
Log.d(TAG, "RELEASE : " + Build.VERSION.RELEASE);
Log.d(TAG, "SDK : " + Build.VERSION.SDK_INT);
RELEASE : 4.3.1
SDK : 18
「API-18」て「Gingerbread」だったけか?
などといつもググっているが.
Dashboards | Android Developers
いい暗記方法ねえかなと思いつつコードで吐く.
for (Field field : Build.VERSION_CODES.class.getDeclaredFields()) {
field.setAccessible(true);
Log.d(TAG, field.get(this) + " -> " + field.getName());
}
1 -> BASE
2 -> BASE_1_1
3 -> CUPCAKE
10000 -> CUR_DEVELOPMENT
4 -> DONUT
5 -> ECLAIR
6 -> ECLAIR_0_1
7 -> ECLAIR_MR1
8 -> FROYO
9 -> GINGERBREAD
10 -> GINGERBREAD_MR1
11 -> HONEYCOMB
12 -> HONEYCOMB_MR1
13 -> HONEYCOMB_MR2
14 -> ICE_CREAM_SANDWICH
15 -> ICE_CREAM_SANDWICH_MR1
16 -> JELLY_BEAN
17 -> JELLY_BEAN_MR1
18 -> JELLY_BEAN_MR2
他の端末で.
RELEASE : 5.1.1
SDK : 22
1 ->BASE
2 -> BASE_1_1
3 -> CUPCAKE
10000 -> CUR_DEVELOPMENT
4 -> DONUT
5 -> ECLAIR
6 -> ECLAIR_0_1
7 -> ECLAIR_MR1
8 -> FROYO
9 -> GINGERBREAD
10 -> GINGERBREAD_MR1
11 -> HONEYCOMB
12 -> HONEYCOMB_MR1
13 -> HONEYCOMB_MR2
14 -> ICE_CREAM_SANDWICH
15 -> ICE_CREAM_SANDWICH_MR1
16 -> JELLY_BEAN
17 -> JELLY_BEAN_MR1
18 -> JELLY_BEAN_MR2
19 -> KITKAT
20 -> KITKAT_WATCH
21 -> L
21 -> LOLLIPOP
22 -> LOLLIPOP_MR1
その端末が知っているOSコードネーム群の最終がその端末のOSコードネームと想像.
Field[] fields = Build.VERSION_CODES.class.getDeclaredFields();
Log.d(TAG, "Name : " + fields[fields.length - 1].getName());
Name : LOLLIPOP_MR1
最終でないことはあり得るのか.
フツーに走査か.
追記:2020-03-13
Kotlin で。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal inline fun Application.showApiVersions() { | |
Build.VERSION_CODES::class.java.declaredFields.forEach { | |
it.isAccessible = true | |
println("# API ${it?.get(this)} - ${it.name}") | |
} | |
} |
追記:2022-01-26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal fun Application.showApiVersions() { | |
Build.VERSION_CODES::class.java.declaredFields.forEach { | |
it.isAccessible = true | |
println("# API ${it?.get(this)} - ${it.name}") | |
} | |
println("# Android ${Build.VERSION.RELEASE} - API ${Build.VERSION.SDK_INT}") | |
} | |
/* | |
@See | |
https://bit.ly/3AzAHvF | |
I: # API 1 - BASE | |
I: # API 2 - BASE_1_1 | |
I: # API 3 - CUPCAKE | |
I: # API 10000 - CUR_DEVELOPMENT | |
I: # API 4 - DONUT | |
I: # API 5 - ECLAIR | |
I: # API 6 - ECLAIR_0_1 | |
I: # API 7 - ECLAIR_MR1 | |
I: # API 8 - FROYO | |
I: # API 9 - GINGERBREAD | |
I: # API 10 - GINGERBREAD_MR1 | |
I: # API 11 - HONEYCOMB | |
I: # API 12 - HONEYCOMB_MR1 | |
I: # API 13 - HONEYCOMB_MR2 | |
I: # API 14 - ICE_CREAM_SANDWICH | |
I: # API 15 - ICE_CREAM_SANDWICH_MR1 | |
I: # API 16 - JELLY_BEAN | |
I: # API 17 - JELLY_BEAN_MR1 | |
I: # API 18 - JELLY_BEAN_MR2 | |
I: # API 19 - KITKAT | |
I: # API 20 - KITKAT_WATCH | |
I: # API 21 - LOLLIPOP | |
I: # API 22 - LOLLIPOP_MR1 | |
I: # API 23 - M | |
I: # API 24 - N | |
I: # API 25 - N_MR1 | |
I: # API 26 - O | |
I: # API 27 - O_MR1 | |
I: # API 28 - P | |
I: # API 29 - Q | |
I: # API 30 - R | |
I: # API 31 - S | |
I: # Android 12 - API 31 | |
*/ |