Ho riscontrato che il comportamento di Build.VERSION.RELEASE e Build.VERSION.CODENAME è molto diverso a seconda che si tratti di una versione di produzione completa del sistema operativo Android o di un'anteprima dello sviluppatore. Siamo andati con il seguente meccanismo. Non è possibile fare affidamento su un solo valore se si desidera tenere conto di più scenari.
Questo è quello che ho trovato è il caso per un Galaxy S7 che esegue una versione di produzione di Nougat e un Nexus 5X con O DP1.
Galaxy S7 Torrone Build.VERSION.BASE_OS: Build.VERSION.CODENAME: REL Build.VERSION.INCREMENTAL: G930FXXU1DQB3 Build.VERSION.PREVIEW_SDK_INT: 0 Build.VERSION.RELEASE: 7.0 Costruire .VERSION.SDK_INT: 24 Build.VERSION.SECURITY_PATCH: 2017-01-01
Nexus 5X O Build.VERSION.BASE_OS: Build.VERSION.CODENAME: O Build.VERSION.INCREM Ental: 3793265 Build.VERSION.PREVIEW_SDK_INT: 1 Build.VERSION.RELEASE: O Build.VERSION.SDK_INT: 25 Build.VERSION.SECURITY_PATCH: 2017-03-05
// release builds of Android (i.e. not developer previews) have a CODENAME value of "REL"
// check this. if it's REL then you can rely on value of SDK_INT (SDK_INT is inaccurate for DPs
// since it has the same value as the previous version of Android)
// if it's not REL, check its value. it will have a letter denoting the Android version (N for Nougat, O for... er... O and so on)
boolean laterThanNougat = false;
if(Build.VERSION.CODENAME.equals("REL")) {
Log.i(TAG, "This is a release build");
// since this is a release build, we can rely on value of SDK_INT
if (android.os.Build.VERSION.SDK_INT > 25) {
Log.i(TAG, "This is later than Nougat");
laterThanNougat = true;
} else {
Log.i(TAG, "This is Nougat or before");
}
} else {
Log.i(TAG, "This is NOT a release build");
// since this is not a release build, we can't rely on value of SDK_INT. must check codename again
if(Build.VERSION.CODENAME.compareTo("N") > 0) {
Log.i(TAG, "This is later than Nougat");
laterThanNougat = true;
} else {
Log.i(TAG, "This is Nougat or before");
}
}
fonte
2017-05-18 14:39:34
è necessaria la versione di rilascio , non la versione di sdk. 'Build.VERSION.RELEASE'.Restituirà una rappresentazione String della versione in esecuzione sul dispositivo; Sono sicuro al 99%. Non l'ho fatto da un po '. – zgc7009
Grazie, 'Build.VERSION.RELEASE' sta restituendo" N " – Exaqt