Making Noise Android

Sometimes, the handset has to make noise to get the user’s attention. Luckily, the Android SDK provides a means for this using the Notification object. Begin by configuring the audio stream type to use when playing a sound. Generally, the most useful stream type is STREAM_NOTIFICATION. You can configure the audio stream type on your notification as follows:

notify.audioStreamType = AudioManager.STREAM_NOTIFICATION;

Now, assign a valid Uri object to the sound member variable and that sound plays when the notification is triggered. The following code demonstrates how to play a sound that is included as a project resource:

notify.sound = Uri.parse(
"android.resource://com.androidbook.simplenotifications/" +
R.raw.fallbackring);

By default, the audio file is played once. As with the vibration, the Notification. FLAG_ INSISTENT flag can be used to repeat incessantly until the user clears the notification. No specific permissions are needed for this form of notification


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Android Topics