Pages

Ads 468x60px

Thursday, September 29, 2011

Android’s HTTP Clients

Jesse Wilson

[This post is by Jesse Wilson from the Dalvik team. —Tim Bray]



Most network-connected Android apps will use HTTP to send and receive data. Android includes two HTTP clients: HttpURLConnection and Apache HTTP Client. Both support HTTPS, streaming uploads and downloads, configurable timeouts, IPv6 and connection pooling.

Apache HTTP Client

DefaultHttpClient and its sibling AndroidHttpClient are extensible HTTP clients suitable for web browsers. They have large and flexible APIs. Their implementation is stable and they have few bugs.

But the large size of this API makes it difficult for us to improve it without breaking compatibility. The Android team is not actively working on Apache HTTP Client.

HttpURLConnection

HttpURLConnection is a general-purpose, lightweight HTTP client suitable for most applications. This class has humble beginnings, but its focused API has made it easy for us to improve steadily.

Prior to Froyo, HttpURLConnection had some frustrating bugs. In particular, calling close() on a readable InputStream could poison the connection pool. Work around this by disabling connection pooling:

private void disableConnectionReuseIfNecessary() {
// HTTP connection reuse which was buggy pre-froyo
if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) {
System.setProperty("http.keepAlive", "false");
}
}

In Gingerbread, we added transparent response compression. HttpURLConnection will automatically add this header to outgoing requests, and handle the corresponding response:

Accept-Encoding: gzip

Take advantage of this by configuring your Web server to compress responses for clients that can support it. If response compression is problematic, the class documentation shows how to disable it.

Since HTTP’s Content-Length header returns the compressed size, it is an error to use getContentLength() to size buffers for the uncompressed data. Instead, read bytes from the response until InputStream.read() returns -1.

We also made several improvements to HTTPS in Gingerbread. HttpsURLConnection attempts to connect with Server Name Indication (SNI) which allows multiple HTTPS hosts to share an IP address. It also enables compression and session tickets. Should the connection fail, it is automatically retried without these features. This makes HttpsURLConnection efficient when connecting to up-to-date servers, without breaking compatibility with older ones.

In Ice Cream Sandwich, we are adding a response cache. With the cache installed, HTTP requests will be satisfied in one of three ways:

  • Fully cached responses are served directly from local storage. Because no network connection needs to be made such responses are available immediately.


  • Conditionally cached responses must have their freshness validated by the webserver. The client sends a request like “Give me /foo.png if it changed since yesterday” and the server replies with either the updated content or a 304 Not Modified status. If the content is unchanged it will not be downloaded!


  • Uncached responses are served from the web. These responses will get stored in the response cache for later.


Use reflection to enable HTTP response caching on devices that support it. This sample code will turn on the response cache on Ice Cream Sandwich without affecting earlier releases:

private void enableHttpResponseCache() {
try {
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
File httpCacheDir = new File(getCacheDir(), "http");
Class.forName("android.net.http.HttpResponseCache")
.getMethod("install", File.class, long.class)
.invoke(null, httpCacheDir, httpCacheSize);
} catch (Exception httpResponseCacheNotAvailable) {
}
}

You should also configure your Web server to set cache headers on its HTTP responses.

Which client is best?

Apache HTTP client has fewer bugs on Eclair and Froyo. It is the best choice for these releases.

For Gingerbread and better, HttpURLConnection is the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. New applications should use HttpURLConnection; it is where we will be spending our energy going forward.

Wednesday, September 28, 2011

Android Gameloft HD Games Nova, Nova 2, Modern Combat, Avatar, Eternal Legacy, Fast 5, Sacred Oddesy, Spiderman, Starfront, Shadow Guardian download




This is a torrent link which includes the most famous High Definition Games by Gameloft. The Games are

1. Nova




2.Modern Combat


3.Nova 2
4.Shadow Guardian

5.Sacred Odyssey
6. Eternal Legacy
7. Fast Five Official Game
8.Starfront
9.Avatar HD

                           

This torrent also includes the data (files to be downloaded after installing the game) for sd card. So, you wont be having to download it once the game is installed, you just have copy and paste these files in the sdcard/gameloft/games directory.

Monday, September 26, 2011

VLC Media Player For Android Free



Get your MKV’s, AVI’s and ANIME’s ready! Android developer/modder extraordinaire, CVPCS, was able to compile a working pre-Alpha version of VLC media player for Android. If you’re unfamiliar with VLC, it’s essentially a open-source (we like those words around here) media player for Windows, Mac and everything in between that allows you to play virtually any video format on your desktop. That alone should help you see the value in bringing this amazing tool to Android.
Because of the way VLC is built, it can’t (or wont) support all Android devices. Instead, it separates them according to your processor, into 2 categories: NEON and NO-NEON. How do you find out if your device is NEON? Simply use a file manager app, dig around in your system files and locate the folder /proc/cpuinfo and then take a look inside. You should see something like this:
Processor : ARMv7 Processor rev 2 (v7l)
processor : 0
BogoMIPS : 1597.74

Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x1
CPU part : 0xc09
CPU revision : 2

Hardware : mapphone_CDMA
Revision : 0000
Serial : 0000000000000000
Take a look at the Features line and look for the word “neon.” If it’s there — then you have yourself a NEON device. If not — then you’ll have to use the NONEON version of VLC. Okay, let’s get to the good stuff. The download. Seeing how this is such an early pre-Alpha build of VLC for Android, CVPCS will not be providing support. If you want to try out VLC for Android still in its early stages:
If you wont a ton more information on VLC for Android, hit up the source link for all the technical details.
Related Posts Plugin for WordPress, Blogger...