Android 通过ADB方式获取&设置音量
创始人
2024-11-04 13:38:49
0

在Android 开发中,会涉及到各种音量调整环节,可以通过Demo的方式实时修改体现也可以通ADB的方式来实现.简单记录一下.

一 获取设备音频全部信息

通过dumpsys 指令获取audio信息,即可获得设备全部信息.

dumpsys audio
二 Android的音量类型(举例:Android 8.1)
    /* These values must be kept in sync with system/audio.h */     /*      * If these are modified, please also update Settings.System.VOLUME_SETTINGS      * and attrs.xml and AudioManager.java.      */     /** Used to identify the default audio stream volume */     public static final int STREAM_DEFAULT = -1;     /** Used to identify the volume of audio streams for phone calls */     public static final int STREAM_VOICE_CALL = 0;     /** Used to identify the volume of audio streams for system sounds */     public static final int STREAM_SYSTEM = 1;     /** Used to identify the volume of audio streams for the phone ring and message alerts */     public static final int STREAM_RING = 2;     /** Used to identify the volume of audio streams for music playback */     public static final int STREAM_MUSIC = 3;     /** Used to identify the volume of audio streams for alarms */     public static final int STREAM_ALARM = 4;     /** Used to identify the volume of audio streams for notifications */     public static final int STREAM_NOTIFICATION = 5;     /** Used to identify the volume of audio streams for phone calls when connected on bluetooth */     public static final int STREAM_BLUETOOTH_SCO = 6;     /** Used to identify the volume of audio streams for enforced system sounds in certain      * countries (e.g camera in Japan) */     public static final int STREAM_SYSTEM_ENFORCED = 7;     /** Used to identify the volume of audio streams for DTMF tones */     public static final int STREAM_DTMF = 8;     /** Used to identify the volume of audio streams exclusively transmitted through the      *  speaker (TTS) of the device */     public static final int STREAM_TTS = 9;     /** Used to identify the volume of audio streams for accessibility prompts */     public static final int STREAM_ACCESSIBILITY = 10;

 Android 12 有新增

/** @hide Used to identify the volume of audio streams for virtual assistant */     public static final int STREAM_ASSISTANT = 11;

 常用的有以下五种:

  • 获取设备的电话音量 - STREAM_VOICE_CALL 
  • 获取设备的系统音量 - STREAM_SYSTEM
  • 获取设备的铃音音量 - STREAM_RING
  • 获取设备的音乐音量 - STREAM_MUSIC
  • 获取设备的闹钟音量- STREAM_ALARM
举例:设置多媒体音量大小
adb shell media volume --show --stream 3 --get   输出:     [v] will control stream=3 (STREAM_MUSIC)     [v] will get volume     [v] Connecting to AudioService     [v] volume is 0 in range [0..15]  # 注:即当前STREAM_MUSIC是0,最小0,最大15
举例:设置多媒体音量大小
adb shell media volume --show --stream 3 --set 10   输出:     [v] will control stream=3 (STREAM_MUSIC)     [v] will set volume to index=10     [v] Connecting to AudioService   # 注:设置系统音量为0(stream=1)后,设备会进入静音模式,之后再修改其他模式音量会失败
Android 11 以上获取/设置方式

较高版本获取/设置有所变更, 官方文档如下:

In Android 11 and Android 12, media utility no longer exists. That's why you got the error since your shell could not find the utility in locations mentioned in its PATH. That utility's commands have been moved to a service name MediaSessionService. To access those commands invoke this service using cmd command.

具体的操作案例演示如下: 

// 必须先建立连接 adb shell cmd media_session   C:\adb>adb shell cmd media_session  volume  --stream 3 --get [V] will control stream=3 (STREAM_MUSIC) [V] will get volume [V] Connecting to AudioService [V] volume is 5 in range [0..15]   C:\adb>adb shell cmd media_session  volume --show --stream 3 --set 11 [V] will control stream=3 (STREAM_MUSIC) [V] will set volume to index=11 [V] Connecting to AudioService

 

相关内容

热门资讯

透视app!aapoker怎么... 透视app!aapoker怎么设置抽水(透视)可以开辅助器(一贯是真的有挂)一、aapoker怎么设...
透视教程!哈糖大菠萝软件下载,... 透视教程!哈糖大菠萝软件下载,wepoker脚本(透视)原先有挂(科技教程)透视教程!哈糖大菠萝软件...
透视总结(WPK)确实有挂(透... 透视总结(WPK)确实有挂(透视)wpk辅助软件(攻略方法);1、wpk辅助软件透视辅助简单,wpk...
透视挂!pokernow辅助工... 透视挂!pokernow辅助工具,哈糖大菠萝怎么挂,真是是真的有挂(攻略教程)1、任何哈糖大菠萝怎么...
透视辅助!aapoker辅助工... 透视辅助!aapoker辅助工具安全吗(透视)发牌逻辑(总是有挂)1、超多福利:超高返利,海量正版游...
透视私人局!hh poker插... 透视私人局!hh poker插件下载,约局吧德州真的有透视挂吗(透视)起初存在有挂(技巧教程)1、构...
透视透视(WPK)切实真的有挂... 透视透视(WPK)切实真的有挂(透视)wpk有作弊吗(攻略方法)1)wpk有作弊吗辅助挂:进一步探索...
透视攻略!epoker有透视吗... 透视攻略!epoker有透视吗,拱趴大菠萝机器人,其实有挂(新2025教程);1、下载好拱趴大菠萝机...
透视科技!aapoker公共底... 透视科技!aapoker公共底牌(透视)辅助器是真的(竟然是有挂)1、每一步都需要思考,不同水平的挑...
透视好友!wepoker有没有... 透视好友!wepoker有没有挂,hhpoker辅助软件(透视)起初是真的有挂(解密教程)1、hhp...