"Android" experiment 7 Bindservice Analog communications deadline submission date 2016.5.3

Source: Internet
Author: User

Experiment 7 Bindservice Analog communication

Purpose

Enables two-way communication between the start-up and Bindservice

Requirements

1) The implementation of a data transfer from the start side to the Bindservice end;

2) realize the use of Bindservice service to play the music in the project source file;

3) enable the audio volume to be controlled by the "add" and "lower" two buttons on the boot side.

4) The implementation of the "Pause" button to control the audio pause playback on the boot side.

Principle

    1. Refer to Lesson plans to understand the communication principles of Bindservice and start-up
    2. Audiomanager's understanding

Audiomanager class is located on Android. Media Pack, this class provides access to control volume and ringtone mode operations.

The Audiomanager instance object is obtained through the Getsystemservice (Context.audio_service) method.

Audiomanager audiomanage = (audiomanager) context.getsystemservice (Context.audio_service);

Audiomanager is the object that we define to control the sound of the system.

Some of the more commonly used methods:

1) adjustvolume (int direction, int flags): Used to control the volume of the phone, when the first parameter passed in is Audiomanager.adjust_lower, you can turn the volume down one unit, incoming AU Diomanager.adjust_raise, you can increase the volume by one unit.

2) Adjuststreamvolume (intstreamtype, int direction, intflags): Adjust phone volume size (in step)

Parameter 1: Sound type, preferably stream_voice_call (call), Stream_system (System sound), stream_ring (ringtone), stream_music (music), Stream_alarm (alarm)

Parameter 2: Adjust the direction of the volume, preferably adjust_lower (lower), adjust_raise (raised), Adjust_same
Parameter 3: Optional flag bit

3) Setstreamvolume (intstreamtype, int index, intflags): Set Volume size directly

4) Getstreamvolume (intstreamtype): Get the current phone volume, the maximum value is 7, the minimum value is 0, when it is 0 o'clock, the phone automatically adjusts the mode to "vibration mode".

5) Setstreammute (Intstreamtype, Boolean State): Mute Set

Some reference codes:

Volume control, initialization definition

Audiomanager Maudiomanager = (audiomanager) getsystemservice (Context.audio_service);

Control the volume increase or decrease in one step, and eject the system default Volume control bar:

Lower the volume, bring up the system volume control

if (flag ==0) {

Maudiomanager. Adjuststreamvolume (Audiomanager.stream_music,audiomanager.adjust_lower,

AUDIOMANAGER.FX_FOCUS_NAVIGATION_UP);

}

Increase volume, bring up the system volume control

ElseIf (flag ==1) {

Maudiomanager. Adjuststreamvolume (Audiomanager.stream_music,audiomanager.adjust_raise,

AUDIOMANAGER.FX_FOCUS_NAVIGATION_UP);

}

Other common methods:

Android Audiomanager Get Volume:

Get the Audiomanager instance first,
Audiomanagermaudiomanager = (Audiomanager) getsystemservice (Context.audio_service);

Call volume

int max = Maudiomanager.getstreammaxvolume (Audiomanager.stream_voice_call);

int current = Maudiomanager.getstreamvolume (Audiomanager.stream_voice_call);

System Volume

int max = Maudiomanager.getstreammaxvolume (Audiomanager.stream_system);

Current = Maudiomanager.getstreamvolume (Audiomanager.stream_system);

Ringtone Volume

max = Maudiomanager.getstreammaxvolume (audiomanager.stream_ring);

Current = Maudiomanager.getstreamvolume (audiomanager.stream_ring);

Music volume

max = Maudiomanager.getstreammaxvolume (audiomanager.stream_music);

Current = Maudiomanager.getstreamvolume (Audiomanager.stream_music);

Prompt for sound volume

max = Maudiomanager.getstreammaxvolume (audiomanager.stream_alarm);

Current = Maudiomanager.getstreamvolume (Audiomanager.stream_alarm);

Maximum volume

Intmaxvolume =maudiomanager.getstreammaxvolume (Audiomanager.stream_music);

Current volume

Intcurrentvolume =maudiomanager.getstreamvolume (Audiomanager.stream_music);

How much to control the volume directly:

if (issilent) {

Maudiomanager.setstreamvolume (audiomanager.stream_music,0,0);

}else{

Maudiomanager.setstreamvolume (audiomanager.stream_music,tempvolume,0);//tempvolume: Absolute Volume

}

Lab Report Requirements

1) write down the steps and contents of the experiment in detail;

2) detailed record of the problems found during the experiment and the method of solving the problem;

3) give the various pages in the process of running the program;

4) Submit documents include: Experimental report, source code, can run the installation program, all files packaging compression;

5) compression Package naming format: Professional + study number + name + experiment 7.rar

"Android" experiment 7 Bindservice Analog communications deadline submission date 2016.5.3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.