Quantcast
Channel: WANEntrepreneur » Tutorials
Viewing all articles
Browse latest Browse all 3

A Closer Look At Using Android Audio Manager In Applications

$
0
0

audio

With Android becoming one of the most popular mobile platforms, developers have started switching to Android app development. Whether you’re inclined on shopping online or want to try hands on the latest game version, Android smartphone enables you to do all this and much more. One of the best assets of Android smartphones is the ease of audio management. On Google Play Store, there’s no dearth of apps that have been specially designed for Android users who want to manage their audio files in a well-organized way. Through this blog, I’ll introduce you to the usage of Audio Manager in Android applications.

What’s Broadcast Intent?

In prior to delving into the world of Android Audio Manager, let me make you familiar with Broadcast Intent. Well, it is actually a hint for applications that a particular audio is about to become ‘noisy’ due to a moderation in the audio outputs. For example, a broadcast intent is being sent when a wired headset is unplugged from a mobile device. Android devices come with Audio Manager class that’s used for controlling such audio streams by pausing or reducing the volume.

What exactly is Android Manager?

android manager

Controlling the ringer volume and ringer profile has always been the key concerns of smartphone users. But, with an Android smartphone in hand, you need not worry about these two things. Android comes with an easy-to-use AudioManager class that provides the user an access to the ringer volume(Notification, Alarm, Media Player etc) and ringer profile(silent, loud, vibrate etc.) controls for the device.

Android Manager- How does it work?

Before you opt to Hire Android App Developers or to start using AndroidManager class, firstly you need to create an object of AndroidManager class. This can be done by calling the getSystemService() method. In this post, I’ll be explaining the process of using Android Manager for setting the device’s ringer mode i.e. Silent, Vibrate and Normal.

Setting the Ringer mode for your Android device

ringer

Well, its quite simple to set the ringer mode for your device programmatically. All you need to do is simply invoke the setRingerMode() method by passing the ringer mode type as a parameter. Mentioned below is the code snippet that will set the device’s ringer mode to Silent:

AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);

 And now, let’s create an Android application that uses the Audio Manager class

Step 1- Create a new Android Application Project

Here, go to File-> New-> Android Application Project and name it as: AudioManagerExample. After this, enter the package name as ‘com.prgguru.example’ and activity name as ‘AudioManagerExample’. Also, choose appropriate values for Minimum Required SDK, Compile with and Target SDK. Once you’re done with selecting these options, click on the ‘Next’ button, followed by clicking on ‘Finish’ button to create the new project.
Step 2- Now, add colors in the colors.xml file that’s available under the values folders. The code snippet for this is mentioned below:

<?xml version="1.0" encoding="UTF-8"?>
<resources >
    <color name="red">#d73249</color>
    <color name="yellow">#ffcb00</color>
     <color name="white">#fff</color>
</resources>

Step 3- Add drawable resources to the drawable.mdpi foler

Download and save the drawable resources. After saving, add them to the drawable-mdpi folder that’s available under res folder:

Step 4- Design the application’s screen

Here, you just need to open the activity_main.xml file and replace it with the below mentioned code snippet:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical" >

For the remaining part of the code snippet, you can refer Google.

Step 5- Implement Audio Manager using Java coding

Now, open the AudioManagerExample.java file and replace it with the below mentioned code:

package com.prgguru.example;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;

 public class AudioManagerExample extends Activity {

// AudioManager Object
    AudioManager mode = null;
    // Buttons to change Ringer mode
    View ringerNormalBtn;
    View vibrateBtn;
    View silentBtn;

For the remaining part of the code snippet, you can refer Google.

Step 6- Test the application

With the step no.5, the application has been created and now its time to run it using the emulator or device. Here, I am assuming that you have connected your actual Android device with your computer. For this, all you need to do is simply right click on the project, choose ‘Run as’ , further choose ‘Android application’ and finally choose the option as either emulator or device.

Wrapping Up

With that, its a wrap on this post that delivered you finest details about Android’s Audio Manager. I’m sure you’d have found the post interesting. Don’t forget to leave your comments/feedback using the comments box provided right under this post.

355 total views, no views today

  Read more...

This article is copyright ©  WANEntrepreneur

The post A Closer Look At Using Android Audio Manager In Applications appeared first on WANEntrepreneur.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images