Making Sounds

Using an audio alert to notify the user of a device event (like incoming calls) is a technique that predates the mobile, and has stood the test of time. Most native phone events, from incoming calls to new messages and low battery, are announced by audible ringtones.

Android lets you play any audio file on the phone as a Notification by assigning a location URI to the sound property, as shown in the following snippet:

notification.sound = ringURI;

To use your own custom audio, push the file onto your device, or include it as a raw resource, as described in Chapter 11.

The following snippet can be added to the announceNewQuake method within the Earthquake Service from the earlier example. It adds an audio component to the earthquake Notification, ringing the default notification ringtone if a significant earthquake (one with a magnitude greater than 6) occurs.

RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); newEarthquakeNotification.sound = ringURI;

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment