ADB Receive Broadcast BOOT_COMPLETE

I want to wait until the Android mobile phone and MediaScanner start up.

Then I want to perform an action using adb.

adb wait-for-device will finish much before the cell phone boot sequence is completed.

How to capture, for example. BOOT_COMPLETE Broadcast through ADB? Something like: wait-for-boot-complete. I do not know if this is possible?

+4
source share
3 answers

You can save a poll for sys.boot_completed or dev.bootcomplete system properties.

As for the code, I don't know which environment and / or scripting language you are using. It is pretty simple. First you need to find which property will be set to “1” when your phone software completes the download. Let them say it is dev.bootcomplete . Then the following command will return control back to your script after loading the phone

 adb wait-for-device shell 'while [[ -z $(getprop dev.bootcomplete) ]] ; do sleep 1; done' 
+11
source

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

It is expected until the ADB daemon is started, then it starts polling the sys.boot_completed property and waits for a value of 1.

It is not as elegant as a single line, but I have a script specified 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 ) 
+4
source

If your device does not have a loaded node (see the shell script in android gives [: not found ), you can try iterating on your computer. Something like this will work:

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

If your device is installed in busybox, you can continue, as Alex P commented:

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

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

0
source

Source: https://habr.com/ru/post/1442358/


All Articles