Programming Tips - Android: TLS versions supported by Android API level

Date: 2021oct8 Platform: Android Keywords: SSL Q. Android: TLS versions supported by Android API level A. If you have levels 16,17,18,19 then TLSv1.1 and TLSv1.2 is available but not enabled by default. You can enable it in code (see code below) Here is the official chart: Client socket: Protocol Supported (API Levels) Enabled by default (API Levels) SSLv3 1-25 1-22 TLSv1 1+ 1+ TLSv1.1 16+ 20+ TLSv1.2 16+ 20+ TLSv1.3 29+ 29+ Server socket: Protocol Supported (API Levels) Enabled by default (API Levels) SSLv3 1-25 1-22 TLSv1 1+ 1+ TLSv1.1 16+ 16+ TLSv1.2 16+ 16+ TLSv1.3 29+ 29+ Source https://developer.android.com/reference/javax/net/ssl/SSLSocket.html To enable where possible with HttpURLConnection:
... HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection instanceof HttpsURLConnection) { HttpsURLConnection sconn = (HttpsURLConnection) connection; final int level = Build.VERSION.SDK_INT; if (level >= 16 && level < 20) { // Get TLSSocketFactory here // https://blog.dev-area.net/2015/08/13/android-4-1-enable-tls-1-1-and-tls-1-2/ sconn.setSSLSocketFactory(new TLSSocketFactory()); } } connection.connect(); ...