編輯:關於Android編程
(1)程序說明
在android API的AudioManager中,提供了調節手機音量的辦法。
audioMa.adjustVolume(AudioManager.ADJUST_LOWER, 0);
audioMa.adjustVolume(AudioManager.ADJUST_RAISE, 0);也可以調節手機聲音的模式為震動或者靜音
audioMa.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audioMa.setRingerMode(AudioManager.RINGER_MODE_SILENT);
audioMa.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
(2)布局文件
(3)代碼:
package com.liuzuyi.soundmode; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; public class MainActivity extends Activity { private ImageView myimage; private ImageButton downbutton; private ImageButton upbutton; private ImageButton normalbutton; private ImageButton mutebutton; private ImageButton vibratebutton; private ProgressBar myprogress; private AudioManager audioMa; private int volume; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); audioMa =(AudioManager)getSystemService(Context.AUDIO_SERVICE); myimage = (ImageView)findViewById(R.id.myImage); myprogress =(ProgressBar)findViewById(R.id.myProgress); downbutton =(ImageButton)findViewById(R.id.downButton); upbutton =(ImageButton)findViewById(R.id.upButton); normalbutton=(ImageButton)findViewById(R.id.normalButton); mutebutton=(ImageButton)findViewById(R.id.muteButton); vibratebutton=(ImageButton)findViewById(R.id.vibrateButton); volume =audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); int mode =audioMa.getRingerMode(); if(mode == AudioManager.RINGER_MODE_NORMAL ){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.normal)); } else if(mode == AudioManager.RINGER_MODE_SILENT){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.mute)); } else if(mode == AudioManager.RINGER_MODE_VIBRATE){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.vibrate)); } downbutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { audioMa.adjustVolume(AudioManager.ADJUST_LOWER, 0); volume = audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); int mode =audioMa.getRingerMode(); if(mode == AudioManager.RINGER_MODE_NORMAL ){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.normal)); } else if(mode == AudioManager.RINGER_MODE_SILENT){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.mute)); } else if(mode == AudioManager.RINGER_MODE_VIBRATE){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.vibrate)); } } }); upbutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { audioMa.adjustVolume(AudioManager.ADJUST_RAISE, 0); volume = audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); int mode =audioMa.getRingerMode(); if(mode == AudioManager.RINGER_MODE_NORMAL ){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.normal)); } else if(mode == AudioManager.RINGER_MODE_SILENT){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.mute)); } else if(mode == AudioManager.RINGER_MODE_VIBRATE){ myimage.setImageDrawable(getResources().getDrawable(R.drawable.vibrate)); } } }); normalbutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { audioMa.setRingerMode(AudioManager.RINGER_MODE_NORMAL); volume = audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); myimage.setImageDrawable(getResources().getDrawable(R.drawable.normal)); } }); mutebutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { audioMa.setRingerMode(AudioManager.RINGER_MODE_SILENT); volume = audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); myimage.setImageDrawable(getResources().getDrawable(R.drawable.mute)); } }); vibratebutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { audioMa.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); volume = audioMa.getStreamVolume(AudioManager.STREAM_RING); myprogress.setProgress(volume); myimage.setImageDrawable(getResources().getDrawable(R.drawable.vibrate)); } }); } }
這幾天被AsyncTask虐得不行,在此總結下 首先: AsyncTask的參數介紹 在開發Android移動客戶端的時候往往要使用多線程來進行操作,我們通常會
今天是2013年的最後一天了,這裡首先提前祝大家新年快樂!同時,本篇文章也是我今年的最後一篇文章了,因此我想要讓它盡量有點特殊性,比起平時的文章要多一些特色
問題 在Android中使用內嵌的WebView加載HTML網頁時,如果html頁面中存在輸入框。那麼在有些手機設備中,當輸入框獲取焦點時,系統輸入法鍵盤無法正確彈出,從
開發中碰到問題之後實現的,覺得可能有的開發者用的到或則希望獨立成一個小功能DEMO,所以就放出來這麼一個DEMO。原本覺得是最後完成後發網站客戶端的,可是這樣體現不出一個