Experiment 7 bindservice simulated Communication

Source: Internet
Author: User
Lab report

Course name

Mobile Internet Development Based on Android platform

Lab date

2016.04.20

Lab project name

Bindservice analog communication

Lab location

S3002

Lab type

□Validation √ design □comprehensive

Learning hour

6

I,Lab objectives and requirements(Knowledge points involved and required in this experiment)

1. Data is transferred from the startup end to the bindservice end;

2. Use bindservice to play the music in the project source file;

3. Enable the "increase" and "decrease" buttons on the boot end to control the audio volume.

4. Enable the "pause" button on the startup end to control the pause of audio playback.

Ii. experiment environment(Hardware and related software used in this experiment)

(1) PC

(2) Operating System: Windows XP

(3) software: Eclipse, jdk1.6, Android SDK, ADT

Iii. experiment content and steps

Implement bidirectional communication between the initiator and bindservice

1) adjustvolume (INT direction, int flags): used to control the volume of the phone. When the first parameter is set to audiomanager. when adjust_lower is used, you can reduce the volume by one unit and transfer it to audiomanager. when adjust_raise is used, you can increase the volume by one unit.

2) adjuststreamvolume (intstreamtype, int ction, intflags): (adjust the volume of the phone in step size)

3) setstreamvolume (intstreamtype, int index, intflags): directly set the volume.

4) getstreamvolume (intstreamtype): obtains the volume of the current mobile phone. The maximum value is 7 and the minimum value is 0. When the value is 0, the mobile phone automatically adjusts the mode to "vibrate ".

5) setstreammute (intstreamtype, Boolean State): sets mute.

Iv. Experiment results(The source program list, running results, experiment conclusions, and design drawings of this experiment)

Code:

XML

<Linearlayout xmlns: Android =Http://schemas.android.com/apk/res/android"

Xmlns: Tools =Http://schemas.android.com/tools"

Android: Orientation ="Vertical"

Android: layout_width ="Fill_parent"

Android: layout_height ="Fill_parent">

 

<Button Android: Id ="@ + ID/btnplay"

Android: layout_width ="Fill_parent"

Android: layout_height ="Wrap_content"

Android: text ="Play Music"/>

 

<Button

Android: Id ="@ + ID/btnpause"

Android: layout_width ="Match_parent"

Android: layout_height ="Wrap_content"

Android: text ="Pause music"/>

 

<Linearlayout Android: Orientation ="Horizontal"

Android: layout_width ="Wrap_content"

Android: layout_height ="Wrap_content"

Android: layout_gravity ="Center_horizontal">

<Button Android: Id ="@ + ID/btnupper"

Android: text ="Volume+"

Android: layout_width ="Wrap_content"

Android: layout_height ="Wrap_content"/>

<Button Android: Id ="@ + ID/btnlower"

Android: text ="Volume-"

Android: layout_width ="Wrap_content"

Android: layout_height ="Wrap_content"/>

</Linearlayout>

</Linearlayout>

 

Main

Public ClassMainactivityExtendsActivity {

PrivateButton btnplay =Null, Btnupper =Null, Btnlower =Null, Btnpause =Null;

PrivateMediaplayer =Null;

PrivateAudiomanager =Null;

@ Override

Protected VoidOncreate (bundle savedinstancestate ){

Super. Oncreate (savedinstancestate );

Setcontentview (R. layout.Activity_main);

Audiomanager = (audiomanager) getsystemservice (service.Audio_service);

Btnplay = (button) findviewbyid (R. Id.Btnplay);

Btnpause = (button) findviewbyid (R. Id.Btnpause);

Btnupper = (button) findviewbyid (R. Id.Btnupper);

Btnlower = (button) findviewbyid (R. Id.Btnlower);

Btnplay. setonclicklistener (listener );

Btnupper. setonclicklistener (listener );

Btnlower. setonclicklistener (listener );

Btnpause. setonclicklistener (listener );

}

View. onclicklistener listener =NewView. onclicklistener (){

Public VoidOnclick (view v ){

@ Suppresswarnings ("UNUSED ")

Button BTN = (button) V;

Switch(V. GETID ()){

CaseR. Id.Btnplay:

Mediaplayer = mediaplayer.Create(Mainactivity.This, R. Raw.Nanshannan);

Mediaplayer. setlooping (True);

Mediaplayer. Start ();

Break;

CaseR. Id.Btnpause:

Mediaplayer. Pause ();

Break;

CaseR. Id.Btnupper:

Audiomanager. adjuststreamvolume (audiomanager.Stream_music,

Audiomanager.Adjust_raise,

Audiomanager.Flag_show_ui);

Break;

CaseR. Id.Btnlower:

Audiomanager. adjuststreamvolume (audiomanager.Stream_music,

Audiomanager.Adjust_lower,

Audiomanager.Flag_show_ui);

Break;

}

}

};

}

Running result :()

 

V. Experiment Summary(Analyze the experiment results, experience and suggestions for improvement)

The lab teacher told us that this experiment is relatively difficult, so it is quite stressful to do this experiment. I am a little scared because I am not very interested in the code, and I am more difficult to learn.

In this experiment, I first read the bindservic document provided by the instructor and then run the code. It may not be really understood, and it may be messy. I don't know which one is binding or which transmits communication. According to your understanding, first obtain the audiomanager, then use the button listener to obtain the volume information from the audiomanager, and then adjust the volume size.

When I realized the volume adjustment function based on my understanding and the information I queried, I was very happy.

Lab comments

 

Lab score

 

Instructor Signature: yy-mm-dd

           

 

Experiment 7 bindservice simulated Communication

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.