Thursday, October 23, 2008

NoiseAlert

While on paternity leave, I wrote this first Android application as a kind of remote baby monitor - even though I would never dare to suggesting using it as such in public... The basic functionality is that when running the application monitors the sound volume through the microphone and if it exceeds a certain threshold automatically dials a number which previously has been configured.

Based on existing examples which come with the SDK distribution it is pretty easy to put together the basic application skeleton - including the XML description of the UI layout. If you don't know what you are looking for the documentation on the Android SDK site is a bit sparse but is great to look up details.

The application consists of an Activity, the Android abstraction for a single self-contained screen with some associated behavior and user interaction. This screen has a layout and a main menu defined in XML and provides framework methods to handle I/O and life-cycle events. For simple apps we can also use periodic event handlers to trigger actions directly from the UI thread.

It seems the only way to currently measure the sound input at the microphone is to run the MediaRecorder and use its getMaxAmplitude method to periodically get the maximum sound level since the last call. Setting up the recorder to write to "/dev/null" - the Unix special bit blackhole works just fine, which avoids filling up the flash card and having to deal with cleanup. For added benefit, there is a special graphical widget which displays a bar power meter with the current sound level from 1-10 in green and red depending on the threshold.

When it comes to calling the phone number, Android supports a intents - a framework of publish-subscribe signals which an application can send to get something done without knowing who is registered to handle them. In this case, the standard system phone application happens to be registered for the ACTION_CALL intent which is used to call a number.

The configuration is nearly automatic. A hierarchy of preferences can be described in XML and then loaded to generated a standard preferences screen which happens many common cases: on/off checkbox options, 1 out of N selection lists, text entry fields, etc. When the preference screen returns it has automatically store the results in the applications default preferences DB instance.

Thus writing a simple Android application with a main menu, some settings and a bit of behavior is really that simple.

The application code is open-source and can be found at http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/. Application package can be downloaded from the same site or is available through the Android Market.

3 comments:

  1. Dear Bernhard Suter,

    I am writing to you because there might be an opportunity to distribute your apps “Noise Alert” through our partner network that includes many regional and international mobile operators as well as SonyEricsson Promotions/PLAYNOW portal.

    GETMO Arabia is part of the Arvato Mobile Group, one of the worldwide leading digital solution providers. We manage services for more than 30 mobile operators all over the world and we are a Vodafone Global Partner managing the Vodafone Android App Store aggregation.

    If you are interested please let us know quickly as we are selecting featured apps for our portals in these days.
    Then we can provide you with our standard distribution agreement.

    For more information visit www.arvato-mobile.com

    We are looking forward to hearing from you.

    Best regards

    Emilien

    Emilien Allemand | Business Development & Marketing
    emilien.allemand@getmo.com
    www.getmo.ae

    Dubai Office:
    Reuters Building No.1 | Dubai Media City
    P.O.Box 502003| Dubai | U.A.E.
    fon: +971 4 391 5637
    fax: +971 4 391 6650

    ReplyDelete
  2. Hey Mr Suter,

    Who did your icon. Way cool.

    Jim Pruett
    "Back Seat Driver"
    "Steampunk Speed Limits"

    ReplyDelete
  3. Dear Bernhard Suter,
    Your NoiseAlert apk is amazing.
    I copied the source code from http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/.
    I am getting two errors 1. is at mRecorder.prepare();2. Main_menu.xml showing 6 errors . Please clear my doubts.Is there any way I can download Noisealert project zip file.

    Regards,
    Nandish Patil
    nandish.n@gmail.com

    ReplyDelete