1

Leaving target on API22 and running the app on Android 6 platform device, I see that DefaultHttpClient is still working, even though it isnt supported by the new platform.

How is it possible, does it work in a compatibility mode?

GPack
  • 2,494
  • 4
  • 19
  • 50
  • HttpClient Deprecated since API level 22 .Use HttpURLConnection .http://android-developers.blogspot.in/2011/09/androids-http-clients.html – IntelliJ Amiya Oct 07 '15 at 09:36
  • 1
    @IntelliJAmiya Not all functionality the HttpClient has has been made available in HttpURLConnection. There are plenty of reasons to keep using the DefaultHttpClient. – Daniël van den Berg Oct 07 '15 at 09:38
  • My question is another: how is it possible that it is still working. – GPack Oct 07 '15 at 09:41
  • I hope it will helpful http://stackoverflow.com/questions/32090899/androidhttpclient-and-httpget-api-deprecated-in-android-6-0-marshmallow-api-23 – Ajit Kumar Dubey Oct 07 '15 at 11:24

1 Answers1

0

That it isn't supported does not mean it's been removed. In code you'll often see "deprecated" functions. These are functions that are not supported, but have purposefully not been removed.

In this case, you use the functionality from the Android API22 library. To preserve backwards compatibilty functionality of previous API's is almost never fully removed from the actual Android environment.

When compiling something with API level 22, the APK will actually contain parts of that library. In this case, that means that the DefaultHttpClient from API22 is actually included in your app. It doesn't use the version that is (not) on the phone. What parts are to be included in your app is decided in:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }
}

Everything that is missing from API level 23 but is available in level 17 will get included in your app.

Daniël van den Berg
  • 2,197
  • 1
  • 20
  • 45
  • I think there should be emphasis on the *almost* never. I've seen some methods/classes actually removed from the SDK (like android.provider.Browser.BookmarkColumns), and I wouldn't be surprised if it happened in the actual devices at some point, although I'm sure they'd have a really good reason to do so. It's best to just try to follow the API changes and test applications properly when using deprecated things. – Zharf Oct 07 '15 at 10:37
  • @Zharf added the emphasis ;) – Daniël van den Berg Oct 07 '15 at 11:05
  • But my actual targetSdkVersion is set to 22 not to 23, and im not sure that missing DefaultHttpClient is linked in the APK and used at runtime from that. Have you some docs' link about compiling APK, please? – GPack Oct 07 '15 at 11:06