You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

获取映射Android通话状态码的ADB命令技术求助

Direct ADB Command to Get Android Telecom Call State Code

Got it, let's cut straight to the solution you need — instead of parsing logcat for call state, you can query the Android Telecom service directly via ADB to get the official call state codes defined in the Telecom Call class. Here's how:

First, a quick recap of official call state values

These are the standard constants you're referencing, mapped to their numeric values:

  • STATE_IDLE (0): No active calls
  • STATE_RINGING (1): Incoming call ringing
  • STATE_DIALING (2): Outgoing call being placed
  • STATE_ACTIVE (3): Call is currently active
  • STATE_HOLDING (4): Call is on hold

Core ADB Command to Fetch Call State

Use the dumpsys tool to retrieve Telecom service state, then filter for the current call state:

adb shell dumpsys telecom | grep -oP 'mCallState=\K\w+'

This command returns the string representation of the state (e.g., ACTIVE, RINGING). If you want the numeric code directly, use this extended script to map the string to its official number:

adb shell dumpsys telecom | awk '/mCallState=/ {
    state = substr($1, 12);  # Extract state string after "mCallState="
    switch(state) {
        case "IDLE": print 0; break;
        case "RINGING": print 1; break;
        case "DIALING": print 2; break;
        case "ACTIVE": print 3; break;
        case "HOLDING": print 4; break;
        default: print "Unknown state: " state;
    }
}'

How to Test This

  1. Connect your Android device to your computer and enable USB debugging.
  2. Run the command in different call scenarios:
    • Standby (no calls): Should return 0 (or IDLE)
    • Incoming call ringing: Returns 1 (or RINGING)
    • Dialing an outgoing call: Returns 2 (or DIALING)
    • Active call in progress: Returns 3 (or ACTIVE)
    • Holding a call: Returns 4 (or HOLDING)

Why This Works Better Than Logcat Parsing

  • Direct & Reliable: Queries the system's Telecom service directly, so you don't have to rely on log messages that might be disabled or formatted differently across devices.
  • Script-Friendly: Returns a clean, parseable value that you can use in automation scripts or tools, instead of sifting through log output.

内容的提问来源于stack exchange,提问作者Mohamed Heiba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:21:32