Laman

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.

9/28 Rumah Android

     
    Rumah Android    
   
Google SIM CARD:Google Launch Cellular Service?
September 28, 2011 at 1:55 PM
 

googlesim1 Google SIM CARD:Google  Launch Cellular Service?

A number of people associated with Google (including engineers and co-workers) have received a starter pack which has a Nexus S testing sim-card with other documentation. Each sim-card is associated with various operators such as Orange and Vodafone and this gives us a feeling that Google has plans of becoming a Mobile Virtual Network Operator (MVNO).
New photo of what appears to be a Google Sim Card is circulating the web, raising questions about the possibility of a future cellular service for the search engine giant.  It is unclear if the photo has been edited, as the first sighting comes from Spain and shows a multi colored striped card with the brand name "Google" and a Pin and PUK number.  Word has it that the Sim card is being tested on the Google Nexus S, however these reports have not been confirmed.  There is still the possibility that the photo is a fake.

googlesim2 300x225 Google SIM CARD:Google  Launch Cellular Service?

The idea of Google either launching their own cellular service, or joining forces with another carrier is not farfetched however, especially when you take into consideration the new services Google has launched within the past year.  Much of Google's latest developments focus on communication and social networking (Google Voice, Google+) and it seems that cellular would be a natural progression from these two latest developments.  The photos also show a carrier's name "Google_ES" which would indicate Google Spain.  Is it possible that a new cellular service is set to be tested in Spain?

Posts Related to Google SIM CARD:Google Launch Cellular Service?

   
   
Everything From The Home Screen To Rooting
September 28, 2011 at 8:19 AM
 

android101 420x2501 Everything From The Home Screen To Rooting

Know anyone that's new to Android and could use a schooling on how it all works works? Maybe you know someone interested in a new smartphone and could use an Android education. Well we've got a free guide for you that will take them through just about everything they will need to know about Android to get them started. The guide will take them from a brief history of Android to the home screen interface and what it's all about, the Android Market, and even an explanation on game emulators and rooting (the good and the bad). The guide is called "These Are The Droids You're Looking For: An Android Guide" and you can request it for free right here. I would say this guide is really only for a beginner or someone that has never used and Android device, but at 22 pages long it's also very detailed. Even if you're a pro, this might be worth grabbing to share with others that might need a hand understanding how Android works.

Posts Related to Everything From The Home Screen To Rooting

   
   
Galaxy Players 4.0 and 5.0 available on oct, 16
September 27, 2011 at 8:04 PM
 

players 575px Galaxy Players 4.0 and 5.0 available on oct, 16

The Galaxy Player 5.0 will have a 5-inch WVGA TFT LCD (800×480) and the Galaxy Player 4.0 will have a 4-inch WVGA TFT LCD (800×480). Both will come with Android 2.3.5 and a 3.2MP front camera along with a VGA front camera. Pricing will be $229 for the 4.0 and the $269 for the 5.0.

In addition to the Galaxy Tab 8.9, Samsung also introduced its new line of Galaxy Players tonight, an attractive option for those who want the functionality of an Android-powered Galaxy device without the monthly data charges. And a fine option it is: the Galaxy Player is up-to-snuff with some of the best Android devices on the market. It comes in two flavors: the 4.0 has a 4-inch screen Super WVGA Super Clear LCD at 800 x 480 resolution, while the 5.0 has a 5-inch, WVGA TFT LCD display at 800 x 480 resolution.

The Galaxy Players are powered by Gingerbread 2.3.5, which means they support everything you’ve come to love from your Android smartphone, minus of course the phone calls. Each has 8GB of internal storage with a microSD card slot which can handle up to 32GB. And while Samsung hasn’t officially announced what’s under the hood, whispers at the Samsung Portfolio event suggested a 1 GHz single-core processor with 512 MB of RAM. We’ll confirm that closer to the Oct. 16 release date, when the 4.0 will hit for $ 229 and the 5.0 for $ 269. Photos commence after the break.

Full Specs:

Network WiFi™ 802.11b/g/n
OS Android™ 2.3.5 (Gingerbread)
Display 5" WVGA TFT LCD (800×480) 5.0 / 4" WVGA Super Clear LCD (800×480)
Camera Rear : 3.2MP Camera AF with LED Flash
Front : VGA Camera
Video Format : MPEG4/H263/H264,Divx/Xvid
Playback & Recording: 720p HD Video
Audio MP3, AAC, AAC+, eAAC+, OGG, WMA, FLAC, WAV
3.5mm Ear Jack, FM Radio and Stereo Speaker
Value-addedFeatures Android Market™
Google™Mobile Services : Google™ Talk, Google™ Maps, Books, etc.
Allshare
Task Manager
Voice Recorder
Connectivity Bluetooth® 3.0
Mini USB
Memory 8GB, microSD slot (up to 32GB)
Size 3.07 x 5.56 x 0.46 inches 5.0 / 2.53 x 4.87 x 0.39 inches 4.0
Weight 6.42 ounces 5.0 / 4.27 ounces 4.0
Battery 2,500mAh 5.0 / 1,200mAh 4.0

Posts Related to Galaxy Players 4.0 and 5.0 available on oct, 16

  • samsung galaxy siii 231636188457 Galaxy Players 4.0 and 5.0 available on oct, 16

    Samsung Galaxy SIII Features

    Going with the specifications its expected to obviously be an upgrade of the Galaxy S2 with the Camera being 12Mp, quad-core processor, a super-bright AMOLED ...

  • Samsung Galaxy Z I9013 Galaxy Players 4.0 and 5.0 available on oct, 16

    SAMSUNG GALAXY R I9103 REVIEW

    The Samsung Galaxy R (also accepted as I9103) is the aboriginal handset to airing in the shoes of the Samsung Galaxy S II. A hardly ...

  •  Galaxy Players 4.0 and 5.0 available on oct, 16

    Why Galaxy Ace can’t shoot videos at 720p on 5MP Camera

    Just wanna acquaint you that Have you heard about Samsung Wave 2 with BADA OS it too has 5 mp camera but it shoots at ...

  • ace 300x224 Galaxy Players 4.0 and 5.0 available on oct, 16

    Review For Samsung Galaxy SII

    As the sequel to the bestselling Android phone ever – the Samsung Galaxy S - the latest flagship Sony phone has a lot to live up ...

  • htc sensation xe Galaxy Players 4.0 and 5.0 available on oct, 16

    HTC Sensation XE News

    The rumors can be laid to rest, because HTC has clearly appear its Sensation XE handset, abounding with some upgraded specs and Beats Audio. Powered ...

   
   
Hands on with the Samsung Galaxy Tab
September 27, 2011 at 4:45 PM
 

100 2915 300x2251 Hands on with the Samsung Galaxy Tab

Earlier today we were at the Samsung Galaxy Portfolio Event in New York City, and we got our hands on the Samsung Galaxy Tab 8.9. It is finally going to be available on October 3rd for $ 469 (16GB)  and $ 569 (32GB). The Galaxy Tab 8.9 features a 8.9-inch 1280 X 800 Gorilla Glass display, a NVIDIA Tegra 2 dual-core processor, and like the Galaxy Tab 10.1, it is only 8.6mm thin.

Click here to view the embedded video.

Hit the break for pics of the presentation.

Posts Related to Hands on with the Samsung Galaxy Tab

   
   
WhatsApp Messenger v2.6.7814 for Android
September 27, 2011 at 1:05 PM
 

 WhatsApp Messenger v2.6.7814 for Android

WhatsApp Messenger is a smartphone messenger available for Android, BlackBerry, iPhone, and Nokia phones. WhatsApp uses your 3G or WiFi (when available) to message with friends and family. Switch from SMS to WhatsApp to send and receive messages, pictures, audio notes, and video messages. First year FREE! ($1.99/year after)

WHY USE WHATSAPP:

★ NO HIDDEN COST: Once you and your friends download the application, you can use it to chat as much as you want. Send a million messages a day to your friends for free! WhatsApp uses your Internet connection: 3G/EDGE or Wi-Fi when available.

★ MULTIMEDIA: Send Video, Images, and Voice notes to your friends and contacts.

★ GROUP CHAT: Enjoy group conversations with your contacts.

DOWNLOAD APK HERE

Posts Related to WhatsApp Messenger v2.6.7814 for Android

   
     
 
This email was sent to bestandroidsolutions@live.com.
Delivered by Feed My Inbox
PO Box 682532 Franklin, TN 37068
Create Account
Unsubscribe Here Feed My Inbox