Notice
Recent Posts
Recent Comments
Link
투케이2K
5. (TWOK/UTIL) [Android/Java] C_KeyVolumeEvt - 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스 본문
투케이2K 유틸파일
5. (TWOK/UTIL) [Android/Java] C_KeyVolumeEvt - 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스
투케이2K 2022. 3. 20. 15:17[설 명]
프로그램 : Android / Java
설 명 : 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스
[소스 코드]
package com.example.testapp;
import android.content.Context;
import android.media.AudioManager;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Date;
public class C_KeyVolumeEvt {
/**
* TODO [클래스 설명]
* // -----------------------------------------
* 1. onKeyDown 키 이벤트 발생 시 볼륨 조절 수행 클래스
* // -----------------------------------------
* 2. 호출 방법 : onKeyDown 이벤트 정의 >> 볼륨 업 , 볼륨 다운 이벤트 감지 실시
*
* // TODO [모바일 키 이벤트 발생 체크 부분]
* @Override
* public boolean onKeyDown(int keyCode, KeyEvent event) {
*
*
* // [모바일 디바이스의 볼륨 업 키 이벤트가 발생한 경우]
* if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
* }
*
*
* // [모바일 디바이스의 볼륨 다운 키 이벤트가 발생한 경우]
* if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
* }
*
*
* // [이벤트 종료 리턴]
* return true;
* }
*
* // -----------------------------------------
* */
// TODO [미디어 볼륨 UP]
public static void setMediaVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setMediaVolumeUP() :: 미디어 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [미디어 볼륨 DOWN]
public static void setMediaVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setMediaVolumeDOWN() :: 미디어 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [벨소리 볼륨 UP]
public static void setRingVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setRingVolumeUP() :: 벨소리 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [벨소리 볼륨 DOWN]
public static void setRingVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setRingVolumeDOWN() :: 벨소리 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [알림 볼륨 UP]
public static void setNotiVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setNotiVolumeUP() :: 알림 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [알림 볼륨 DOWN]
public static void setNotiVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setNotiVolumeDOWN() :: 알림 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [시스템 볼륨 UP]
public static void setSystemVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setSystemVolumeUP() :: 시스템 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [시스템 볼륨 DOWN]
public static void setSystemVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setSystemVolumeDOWN() :: 시스템 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [알람 볼륨 UP]
public static void setAlramVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setAlramVolumeUP() :: 알람 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [알람 볼륨 DOWN]
public static void setAlramVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setAlramVolumeDOWN() :: 알람 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [통화 볼륨 UP]
public static void setVoiceVolumeUP(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setVoiceVolumeUP() :: 통화 볼륨 UP 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
// TODO [통화 볼륨 DOWN]
public static void setVoiceVolumeDOWN(Context mContext) {
try {
Log.i("---","---");
Log.d("//===========//","================================================");
Log.i("","\n"+"[C_KeyVolumeEvt >> setVoiceVolumeDOWN() :: 통화 볼륨 DOWN 이벤트 지정]");
Log.d("//===========//","================================================");
Log.i("---","---");
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
}
catch (Exception e){
e.printStackTrace();
}
}
} // TODO [클래스 종료]
반응형
'투케이2K 유틸파일' 카테고리의 다른 글
Comments