ADB Receive broadcast BOOT_COMPLETE

前端 未结 3 1336
借酒劲吻你
借酒劲吻你 2020-12-05 22:20

I want to wait until the android mobile phone has started and the MediaScanner is done.

Afterwards I want to perform an action using adb.

adb wait-for-devic

相关标签:
3条回答
  • 2020-12-05 22:39

    You can keep polling for sys.boot_completed or dev.bootcomplete system properties.

    As for the code, I do not know what environment and/or scripting language you are using. It's pretty straightforward. First you need to find which property is being set to "1" up on boot completion by your phone's software. Let's say it is dev.bootcomplete. Then the following command would return control back to your script after the phone is booted up

    adb wait-for-device shell 'while [[ -z $(getprop dev.bootcomplete) ]] ; do sleep 1; done'
    
    0 讨论(0)
  • 2020-12-05 22:55

    For those of you working in a Windows environment, this batch script works for me.

    It waits until the ADB daemon is running, then begins polling the sys.boot_completed property and waiting for a value of 1.

    It's not as elegant as a single line, but I have the script listed in my PATH environment variable so it can be called directly.

    adb wait-for-device
    
    :CheckAgain
    set value=
    for /f "delims=" %%a in ('adb shell getprop sys.boot_completed') do @set value=%%a
    
    IF NOT "%value%" == "1" (
        timeout /t 2 /nobreak >NUL
        goto CheckAgain
    )
    
    0 讨论(0)
  • 2020-12-05 22:59

    If your device does not have busybox installed (see shell script in android gives [: not found), you can try to iterate in your computer. Something like this would work:

    while [ `adb shell getprop dev.bootcomplete` -nq "1" ] ; do sleep 1; done
    

    If your device have busybox installed, you can proceed as Alex P. commented:

    adb shell 'while [ ""`getprop dev.bootcomplete` != "1" ] ; do sleep 1; done'
    

    Of course the syntax depends on your machine (POSIX, etc).

    0 讨论(0)
提交回复
热议问题