O'Reilly logo

Android Application Development For Dummies, 2nd Edition by Donn Felker, Michael Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with the Android Framework Classes

This section gets into the good stuff — the nitty-gritty of Android development and its Android framework classes! Yes, activities and views are integral parts of the system, but they’re simply the “plumbing” that’s required in any modern operating system (in one capacity or another). The real fun is just about to start.

The following sections describe how to check the state of the phone ringer to determine whether it’s in normal mode (ringing loud and proud) or silent mode. At this point, you can begin to start toggling the phone’s ringer mode.

Getting good service

To access the Android ringer, you’ll need lots of access to the AudioManager in Android, which is responsible for managing the ringer state, so you should initialize it in onCreate().

remember.eps All important initialization needs to happen in onCreate().

You first need to create a private class-level AudioManager variable by the name of mAudioManager. Type this name at the top of your class file, directly after the class declaration line, as shown in Listing 5-3.

Listing 5-3: Adding the Class-Level AudioManager Variable

package com.dummies.android.silentmodetoggle;

import android.app.Activity;

import android.media.AudioManager;4

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class MainActivity extends Activity {

private AudioManager mAudioManager; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required