Android 2.2 Froyo browser
HTML5, accelerometer, Flash Player 10.1 and more
About 4 min reading time
Android 2.2 (also known as Froyo) is now with us**. Every Nexus One received the update before July, 4th and other models will have the update very soon. Also, many new devices (like Motorola Droid 2) will come with Android 2.2 very soon.
Unfortunately, the Android team has zero documentation, posts or information about browser compatibility. For this new version, it was not an exception.
The promises #
In the last Google IO, there was a great Keynote about Android 2.2 new browser features (see video1 -starting at 6:00- and video2). I've to admit that I was pretty excited about this new APIs that could be available to web developers. The promises (and the demos shown) were:
- Access to magnetometer and accelerometer
- Access to camera
- Access to API for voice recognition and speech
- Flash Player 10.1 and Adobe AIR 2.0 support
The testing #
So, after having the final 2.2 Android OS version on my Nexus One, I've started some tests and here is what I've found:
- JavaScript performance was announced to be 2x-3x faster than before thanks to the new V8 JavaScript engine. It seems faster, yes.
- JavaScript code runs on background when you switch to other browser tab, like in iOS 4.
- Android browser now supports File Upload. As I mention in Chapter 6, Android -as iOS and webOS- did not understand
<input type="file" />
. When you click "Choose File" you will get a popup menu with options to: select a file from the Gallery, from the music collection or from the sound recorder, where you can create an on-the-fly audio to upload. I've also an option "Documents to Go" that allows me to select any file on the SD card. I'm not sure why "Documents to Go" (an application available in Android Market) is listed here and if we can add more applications to this list (maybe using some Intention). - Android browser still does NOT support Animated GIF nor SVG. I've found an official response about SVG: *"*We have chosen intentionally to not support SVG in the browser to save space; full SVG adds over 1M to the webkit image size."
- Flash Player 10.1 works really great. There are some bugs and problems with some Flash-enabled websites, but I've tried many different websites and Flash is working good and surprisingly fast. You can press-and-hold the Flash movie to get a full-screen button for that particular movie. You have to use the back button to return from full-screen mode.
- I've been in AIR for Android Prerelease program, but I couldn't install it yet on my device, so I don't have an opinion yet.
- Now it appears to have a little support for the HTML5's video tag, but my tests indicate that only work if we provide JavaScript controls to play and stop and it doesn't work so well.
- I could not find any online reference, documentation or sample about those new APIs announced for accelerometer, camera, etc. So, I created a JavaScript object browser (available at mobilexweb.com/tests/object or typing ad.ag/gtwjmg in your mobile browser (that is a Mobile Tiny URL).
New APIs #
Looking for any new API to access the promised features, I've found some new APIs:
- There is a property to query about the current connection type: navigator.connection.type. There is also a navigator.connection enumeration, having the possible values: UNKNOWN, ETHERNET, WIFI, CELL_2G, CELL_3G. And IT WORKS! Then, you can decide what to do depending on the user's connection:
if (navigator.connection.type==navigator.connection.WIFI) { }
- The boolean navigator.onLine can be used to know if the device is connected or not to the web (remember that with HTML 5 we can make an offline webapp, see Chapters 9 and 12). Events like ononline and onoffline are working fine to detect changes in the connection (even when we change from 3G to WIFI, the online event is fired).
- If we use the W3C's Geolocation API (as we've seen in Chapter 11), the position object received has a coord.heading property that I supposed that can be the way to access the magnetometer information. But that property has always "null".
- I have found navigator.isApplicationInstalled(app_name, callback) that it is supposed to look for a native application installed on the device. I've tried several ways to query and I always get a false parameter in the callback. I've found this API implemented in the WebKit open source project, but no sample or information about it. It could be great if it works. As I mention in Chapter 6, using Intention URI-schemes you can call a native application from the browser in Android (in iOS too), but you don't know if the app is installed or not.
- I have also found navigator.registerProtocolHandler(scheme, url, title) and navigator.registerContentHandler(mime_type, url, title). I've executed them but nothing happens and appears to not being working. The WebKit open source project C++ code seems to work, but nothing happens in the final browser. These are APIs from the Web Application specification and could be great, if working. We can then register our web application to be default handler for a MIME type (for example, the browser could open our website when the user clicks on a DOC file) or for a protocol (the WebKit C++ code says that we can apply for a handler of any protocol different to http, https or file).
What about the promises? I couldn't find any new API for those features. I have still hope that a hidden API is available but, if not, maybe the solution can be going through a Flash Player movie (I'm working on testing this for a future post). I'm happy with some of the new features in Froyo, but I'm still unhappy for not having official documentation about browser features. Android team, it's time to work on it!
If anyone found any other APIs or new features, feel free to add it here or contact me by twitter.