【实现手机音量的控制】
package com.example.yltj;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
/***
* 系统音量控制器
*
* @author wxs
*
*/
public class AudioUtil {
/**
* 音量加
*
* @param ac
*/
public static boolean soundUP(Activity ac) {
return soundCtrl(1, ac);
}
/**
* 音量减
*
* @param ac
*/
public static boolean soundDOWN(Activity ac) {
return soundCtrl(0, ac);
}
private static boolean soundCtrl(int flag, Activity ac) {
AudioManager mAudioManager = (AudioManager) ac.getSystemService(Context.AUDIO_SERVICE);
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
if (flag == 0) {
if (currentVolume == 0) {
return false;
}
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP);
return true;
} else {
if (currentVolume == maxVolume) {
return false;
}
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FX_FOCUS_NAVIGATION_UP);
return true;
}
}
}
资源文件列表
YLTJ/.classpath , 475
YLTJ/.project , 840
YLTJ/.settings/org.eclipse.jdt.core.prefs , 177
YLTJ/AndroidManifest.xml , 859
YLTJ/bin/AndroidManifest.xml , 859
YLTJ/bin/YLTJ.apk , 302374
YLTJ/bin/classes/com/example/yltj/AudioUtil.class , 1106
YLTJ/bin/classes/com/example/yltj/BuildConfig.class , 341
YLTJ/bin/classes/com/example/yltj/MainActivity.class , 1535
YLTJ/bin/classes/com/example/yltj/R$attr.class , 334
YLTJ/bin/classes/com/example/yltj/R$dimen.class , 455
YLTJ/bin/classes/com/example/yltj/R$drawable.class , 401
YLTJ/bin/classes/com/example/yltj/R$id.class , 387
YLTJ/bin/classes/com/example/yltj/R$layout.class , 397
YLTJ/bin/classes/com/example/yltj/R$menu.class , 382
YLTJ/bin/classes/com/example/yltj/R$string.class , 466
YLTJ/bin/classes/com/example/yltj/R$style.class , 425
YLTJ/bin/classes/com/example/yltj/R.class , 653
YLTJ/bin/classes.dex , 817316
YLTJ/bin/dexedLibs/android-support-v4-b7b218f4e699b954bf567f3cdbbc5302.jar , 273766
YLTJ/bin/res/crunch/drawable-hdpi/ic_launcher.png , 3493
YLTJ/bin/res/crunch/drawable-mdpi/ic_launcher.png , 2028
YLTJ/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 4977
YLTJ/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 8941
YLTJ/bin/resources.ap_ , 24033
YLTJ/gen/com/example/yltj/BuildConfig.java , 158
YLTJ/gen/com/example/yltj/R.java , 2597
YLTJ/ic_launcher-web.png , 85765
YLTJ/libs/android-support-v4.jar , 758727
YLTJ/proguard-project.txt , 781
YLTJ/project.properties , 563
YLTJ/res/drawable-hdpi/ic_launcher.png , 5199
YLTJ/res/drawable-mdpi/ic_launcher.png , 2894
YLTJ/res/drawable-xhdpi/ic_launcher.png , 7679
YLTJ/res/drawable-xxhdpi/ic_launcher.png , 14333
YLTJ/res/layout/activity_main.xml , 936
YLTJ/res/menu/main.xml , 366
YLTJ/res/values/dimens.xml , 220
YLTJ/res/values/strings.xml , 229
YLTJ/res/values/styles.xml , 697
YLTJ/res/values-v11/styles.xml , 334
YLTJ/res/values-v14/styles.xml , 391
YLTJ/res/values-w820dp/dimens.xml , 381
YLTJ/src/com/example/yltj/AudioUtil.java , 1232
YLTJ/src/com/example/yltj/MainActivity.java , 772
