- 喚醒屏幕操作
os.system("adb shell input keyevent KEYCODE_POWER")
or
os.system('adb shell input keyevent 26')
- 解鎖屏幕
# 屏幕從(500,700)滑動(dòng)到(500,50),延遲200號(hào),毫秒
os.system("adb -s shell input swipe 500 700 500 50 200" )
# 輸入密碼
os.system('adb shell input text 1111')
- 關(guān)閉和開(kāi)啟屏幕樣例
import datetime,os
# 手機(jī)電源開(kāi)關(guān)
def power_switch(device='',p_num='0號(hào)'):
hour = datetime.datetime.today().strftime('%H')
adb_msg = os.popen('adb -s %s shell dumpsys window policy' % device)
phone_msg = adb_msg.buffer.read().decode(encoding='utf-8')
# 10:00~21:00,使手機(jī)處于亮屏和解鎖狀態(tài)
if '10' <=hour <= '21':
if 'mAwake=true' in phone_msg and 'mInputRestricted=false' in phone_msg:
print('%s手機(jī),亮屏?xí)r段,####已亮屏,已解鎖####'%p_num)
logger.info('%s手機(jī),亮屏?xí)r段,####已亮屏,已解鎖####'%p_num)
elif 'mAwake=true' in phone_msg:
print('%s手機(jī),亮屏?xí)r段,****已亮屏,執(zhí)行解鎖****'%p_num)
logger.info('%s手機(jī),亮屏?xí)r段,****已亮屏,執(zhí)行解鎖****' % p_num)
# 屏幕從(500,700)滑動(dòng)到(500,50),延遲200號(hào),毫秒
os.system("adb -s %s shell input swipe 500 700 500 50 200" % device)
else:
print('%s手機(jī),亮屏?xí)r段,====執(zhí)行亮屏和解鎖====' % p_num)
logger.info('%s手機(jī),亮屏?xí)r段,====執(zhí)行亮屏和解鎖====' % p_num)
os.system("adb -s %s shell input keyevent KEYCODE_POWER" % device)
# 屏幕從(500,700)滑動(dòng)到(500,50),延遲200號(hào),毫秒
os.system("adb -s %s shell input swipe 500 700 500 50 200" % device)
else:
# 處于息屏狀態(tài)
if 'mAwake=true' in phone_msg:
print('%s手機(jī),非亮屏?xí)r段,====已亮屏,關(guān)閉亮屏====' % p_num)
logger.info('%s手機(jī),非亮屏?xí)r段,====已亮屏,關(guān)閉亮屏====' % p_num)
os.system("adb -s %s shell input keyevent KEYCODE_POWER" % device)
else:
print('%s手機(jī),非亮屏?xí)r段,====未亮屏====' % p_num)
logger.info('%s手機(jī),非亮屏?xí)r段,====未亮屏====' % p_num)
- 重新啟動(dòng)手機(jī)app
mFocusedActivity = os.popen("adb shell dumpsys activity | grep 'mFocusedActivity' | awk '{print $4}' | awk -F '/' '{print $1}'").read().strip('\n')
if mFocusedActivity == 'com.eg.android.AlipayGphone':
print("APP已啟動(dòng),停止APP,等待重新啟動(dòng)")
os.system('adb shell am force-stop com.eg.android.AlipayGphone')
time.sleep(1)
print("啟動(dòng)app")
os.system('adb shell am start -n com.eg.android.AlipayGphone/com.eg.android.AlipayGphone.AlipayLogin activity')
以上操作需要adb環(huán)境已經(jīng)搭建好,使用以下命令查看連接設(shè)備
C:\Users\enmonster>adb devices
List of devices attached
97dc2d9 device
想獲取某個(gè)APP名稱(chēng)用于啟動(dòng)時(shí),手機(jī)先打開(kāi)APP,然后執(zhí)行以下命令文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-502055.html
adb shell dumpsys window windows |grep "Current"
參考:https://www.cnblogs.com/Kirito-Asuna-Yoyi/p/Python-ADB1.html
https://blog.csdn.net/weixin_40895135/article/details/121487532
https://wenku.baidu.com/view/60353365e75c3b3567ec102de2bd960590c6d9db.html文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-502055.html
到了這里,關(guān)于[1159]adb判斷手機(jī)屏幕狀態(tài)并點(diǎn)亮屏幕的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!