Detect when Android emulator is fully booted

守給你的承諾、 提交于 2019-11-30 11:20:03

问题


I want to create a script where I start an emulator and after the system is fully booted, I want to install an .apk.

How can I know when the emulator is fully booted so I can run the install command? Here http://developer.android.com/guide/developing/tools/adb.html it is said that adb wait-for-device install <app>.apk is not correct.

So how can I achieve this? Is it possible? Is my only option to sleep for a few minutes until I can be sure that the emulator is started?


回答1:


adb shell getprop init.svc.bootanim

This will tell you whether or not the boot animation is running. It's what we use on our headless build server to check if the emulator is up. The sys.boot_completed from dac2009 is what lead me to find that flag. We use init.svc.bootanim instead because boot_completed has a tendency of triggering too early.




回答2:


while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done

This code gets the information from sys.boot_completed if the system boot is complete, removes a newline and compares the resulting value to 1. If its unequal 1/ not booted completly/ it will just sleep 1 second and tries again.

Just put your adb install... after this line of code.




回答3:


Im not sure if this works on all devices, but it works on the ones I have tested.

If you go into the shell, you can type getprop, and get a list of phone properties. There should be one called "sys.boot_completed".

If you type "getprop sys.boot_completed" it will respond "1" if the system is booted, and an empty string if the system is not booted.




回答4:


Just run emulator with -delay-adb flag and then run adb wait-for-device. adb will exit when the emulator booted.




回答5:


You can set a broadcast receiver which can notify that the device boot is complete

android:name="android.intent.action.BOOT_COMPLETED"



回答6:


You may parse the stdout output of the emulator if you start it with "-logcat VERBOSE" and wait for a message which indicates that the emulator is booted.

I didn't saw any good message right now in the output, but you may write an app which is listening for "android.intend.action.BOOT_COMPLETED" and writes something to the log.

Refer http://developer.android.com/guide/developing/tools/emulator.html for more info.



来源:https://stackoverflow.com/questions/3634041/detect-when-android-emulator-is-fully-booted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!