rss
twitter
facebook

Friday, May 21, 2010

Android 2.2 Platform Highlights


The Android 2.2 platform introduces many new and exciting features for users and developers. This document provides a glimpse at some of the new user features and technologies in Android 2.2. For more information about the new developer APIs, see the Android 2.2 version notes.


New User Features


Home


New Home screen tips widget assists new users on how to configure the home

screen with shortcuts and widgets and how to make use of multiple home screens.


The Phone, applications Launcher, and Browser now have dedicated shortcuts on

the Home screen, making it easy to access them from any of the 5 home screen panels.


Exchange support


Improved security with the addition of numeric pin or alpha-numeric password

options to unlock device. Exchange administrators can enforce password policy

across devices.

Remote wipe: Exchange administrators can remotely reset the device to

factory defaults to secure data in case device is lost or stolen.

Exchange Calendars are now supported in the Calendar application.

Auto-discovery: you just need to know your user-name and password to easily

set up and sync an Exchange account (available for Exchange 2007 and higher).

Global Address Lists look-up is now available in the Email application, enabling

users to auto-complete recipient names from the directory.


Camera and Gallery


Gallery allows you to peek into picture stacks using a zoom gesture.

Camera onscreen buttons provide easy access to a new UI for controlling zoom,

flash, white balance, geo-tagging, focus and exposure. Camcorder also provides

an easy way to set video size/quality for MMS and YouTube.


With the LED flash now enabled for the Camcorder, videos can be shot at night

or in low light settings.


Portable hotspot


Certain devices like the Nexus One can be turned into a portable Wi-Fi hotspot
that can be shared with up to 8 devices.

You can use your Android-powered phone as a 3G connection for a Windows or

Linux laptop by connecting their phone to the computer with a USB cable. The connection is then shared between the two devices.



Multiple keyboard languages


Multi-lingual users can add multiple languages to the keyboard and switch

between multiple Latin-based input languages by swiping across the space

bar. This changes the keys as well as the auto-suggest dictionary.



Improved performance


Performance of the browser has been enhanced using the V8 engine, which
enables faster loading of JavaScript-heavy pages.

Dalvik Performance Boost: 2x-5x performance speedup for CPU-heavy code

over Android 2.1 with Dalvik JIT.

The graph to the right shows the performance speedup from Android 2.1 to

Android 2.2 using various benchmark tests. For example, LinPack is now more

than 5 times faster.

Kernel Memory Management Boost: Improved memory reclaim by up to 20x,

which results in faster app switching and smoother performance on memory-

constrained devices.


New Platform Technologies


Media framework


  • New media framework (Stagefright) that supports local file playback and HTTP progressive streaming
  • Continued support for OpenCore in Android 2.2



Bluetooth

  • Voice dialing over Bluetooth

  • Ability to share contacts with other phones

  • Support for Bluetooth enabled car and desk docks

  • Improved compatibility matrix with car kits and headsets


2.6.32 kernel upgrade

  • HIGHMEM support for RAM >256MB

  • SDIO scheduling and BT improvements



New Developer Services



Android Cloud to Device Messaging


Apps can utilize Android Cloud to Device Messaging to enable mobile alert, send to phone, and two-way push sync functionality.

Android Application Error Reports

New bug reporting feature for Android Market apps enables developers to receive crash and freeze reports from their users. The reports will be available when they log into their publisher account.


New Developer APIs


Apps on external storage

Applications can now request installation on the shared external storage (such as an SD card).

Media framework

Provides new APIs for audio focus, routing audio to SCO, and auto-scan of files to media database. Also provides APIs to let applications detect completion of sound loading and auto-pause and auto-resume audio playback.


Camera and Camcorder

New preview API doubles the frame rate from ~10FPS to ~20FPS. Camera now supports portrait orientation, zoom controls, access to exposure data, and a thumbnail utility. A new camcorder profile enables apps to determine device hardware capabilities.

Graphics

New APIs for OpenGL ES 2.0, working with YUV image format, and ETC1 for texture compression.

Data backup

Apps can participate in data backup and restore, to ensure that users maintain their data after performing a factory reset or when switching devices.

Device policy manager

New device policy management APIs allow developers to write "device administrator" applications that can control security features on the device, such as the minimum password strength, data wipe, and so on. Users can select the administrators that are enabled on their devices.

UI framework

New "car mode" and "night mode" controls and configurations allow applications to adjust their UI for these situations. A scale gesture detector API provides improved definition of multi-touch events. Applications can now customize the bottom strip of a TabWidget.

For more information about the new developer APIs, see the Android 2.2 version notes and the API Differences Report.







Wednesday, May 12, 2010

How to play video and audio on Android

There is more than one way, to play media files on an Android phone, let me show you two of them.

Audio:
MediaPlayer is the easier way, if you just want to play an audio file in the background, somewhere in an appliaction. There are no ui controls here, but of course you can use MediaPlayer.stop(), play(), seekTo() ,etc. Just bind the needed functions to a button, gesture, or event. As you can see, it also throws a lot of exceptions, which you need to catch.


  1. public void audioPlayer(String path, String fileName){
  2. //set up MediaPlayer
  3. MediaPlayer mp = new MediaPlayer();
  4. try {
  5. mp.setDataSource(path+"/"+fileName);
  6. // TODO Auto-generated catch block
  7. e.printStackTrace();
  8. } catch (IllegalStateException e) {
  9. // TODO Auto-generated catch block
  10. e.printStackTrace();
  11. } catch (IOException e) {
  12. // TODO Auto-generated catch block
  13. e.printStackTrace();
  14. }
  15. try {
  16. mp.prepare();
  17. } catch (IllegalStateException e) {
  18. // TODO Auto-generated catch block
  19. e.printStackTrace();
  20. } catch (IOException e) {
  21. // TODO Auto-generated catch block
  22. e.printStackTrace();
  23. }
  24. mp.start();
  25. }

Video:
In this example, I open a video file, and decide if I want it to autoplay after it is loaded.
You propably want to store your video files, on the sd card. You can get the path to the sd card via: Environment.getExternalStorageDirectory().


  1. public
    void videoPlayer(String path, String fileName, boolean autoplay){
  2. //get current window information, and set format, set it up differently, if you need some special effects
  3. getWindow().setFormat(PixelFormat.TRANSLUCENT);
  4. //the VideoView will hold the video
  5. VideoView videoHolder = new VideoView(this);
  6. //MediaController is the ui control howering above the video (just like in the default youtube player).
  7. videoHolder.setMediaController(new MediaController(this));
  8. //assing a video file to the video holder
  9. videoHolder.setVideoURI(Uri.parse(path+"/"+fileName));
  10. //get focus, before playing the video.
  11. videoHolder.requestFocus();
  12. if(autoplay){
  13. videoHolder.start();
  14. }
  15. }





Friday, May 7, 2010

Android vs. iPhone : Developer's view

There are a variety of areas to consider regarding the relative restrictiveness of the two platforms.

The Market

Android Market is undoubtedly less restrictive than the App Store when it comes to the submission process. The upside is that you can get pretty much anything you want into the Android Market. The downside is that you can get pretty much anything you want into the Android Market (a market flooded with spam "applications" is in some ways a restriction).

A big negative on the iPhone side is the fact that your options for installing applications that are not in the App Store are limited -- you can either distribute the application as a beta (limited to 100 users) or jailbreak your iPhone. Android, however, allows you to install apps from anywhere, including a web page.

The Applications

One of the core design philosophies of the Android platform is "All Applications are Created Equal", which is supposed to mean that you can freely replace applications on the phone with a third party version. In practice this is not really the case, as many of the Google applications either have special capabilities not available to most applications (see: Android Market) or use undocumented/native APIs (see: Calendar). In addition you are out of luck if you want to run slightly modified versions of the built in applications like the calendar because of code signing issues.

The iPhone on the other hand makes no such claims about equality, and the Apple stance in general is "There is only one way to do it, and that is the Apple way". New for iPhone OS 4.0 is the ability for apps to run in the background. One thing iPhone applications can currently do that Android applications can not is receive push notifications.

The Source

Android is open source - mostly (some firmware components are closed source). Even so, there is some rocket science involved just in getting the Android codebase to compile. In addition Google has sent cease & desist orders for redistributing custom images that include the Android Market and Google Maps application.

The iPhone is completely closed source, and recent changes to the developer agreement have been controversial as they mandate that all apps submitted to the app store be originally written in "Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs"

The SDK

The Android SDK can be freely downloaded; the iPhone SDK requires free user registration to download. Android development can be done under Mac OS X, Windows or Linux, while iPhone development is only possible under Mac OS X. You'll also need to pay for the $99 iPhone developer account if you want to test your software on an actual device (rather than the emulator).

The Userbase

And last but certainly not least, the userbase. When this answer was originally written the iPhone had a much larger userbase and was growing much faster than Android. This is changing as Android begins to support multiple carriers and hardware platforms (see: the Open Handset Alliance). The list of devicesrunning Android is now quite long although none yet match the popularity of the iPhone. It is safe to say that the iPhone will still be the dominant smartphone platform for at least the next year or two.

Wednesday, May 5, 2010

Hidden features of Android development

Hopefully there aren't too many hidden, hidden features - but here's some of the less well known and non-intuitive features available for Android that will definitely make your life easier and your apps better.

  • All the source code for the platform and all the non-Google native apps is available for you to browse, download, borrow, or steal from the Android Open Source project.
  • Using the resources framework, creating localized versions of your app is as simple as adding a new annotated subfolder (Eg. values-fr) that contains an XML file with strings in a different language (Eg. French). Android will choose the right folder at runtime for you.
    • The same resources framework lets you use alternate layouts for different hardware configurations, screen pixel densities, and input devices just by dropping them in named folder.
  • Since Android 1.6, your app can produce results that will appear in the results from a homescreenQuick Search Box search.
  • Using Intents and Intent Filters your apps can make and service anonymous requests for an action to be completed (Eg. Where requesting a table booking from Open Table).
    • They can request an unknown application to complete an action without needing to know which application(s) can fulfill that request
    • Your app can fulfill requests from unknown apps to complete actions without needing to know which apps will make the requests. Play this right and you can create the 'default' Twitter app, or booking app, etc.
  • Using Alarms you can set your app to complete tasks at predetermined times, even if your app isn't running.
    • You can save a lot of battery life using the setInexactRepeating method to schedule regular events (like server polling or updates). It will synchronize alarms from multiple apps to occur at the same time rather than adhoc.
  • Using the Preferences framework you can create settings screens for your apps in the same style as the system settings. You can even incorporate system settings screens (Eg. Security and Location) into your application's settings hierarchy.
  • Using the AudioTrack and AudioRecord APIs, you can stream audio data directly from and to the PCM audio buffers.

Also with regard to best practices, you may want to check out Android coding style:

http://source.android.com/submit-patches/code-style-guide

as well as the eclipse code and imports formatters (android-formatting.xml, android.importorder) which are found in the platform source code under development/ide/eclipse