python 呼叫adb開啟app

2021-08-20 04:24:40 字數 1784 閱讀 7610

通過python xx.py來執行

# -*- coding: utf-8 -*-

""""""

import time

import traceback

import os

def screenshot_prepare():

""""""

try:

displaypowerstate = os.popen("adb shell dumpsys power | grep 'display power: state=' | awk -f '=' ''").read().strip('\n')

#print(displaypowerstate)

if displaypowerstate == 'off':

print("喚醒螢幕")

os.system('adb shell input keyevent 26')

else:

print("螢幕已開啟不需要喚醒")

isstatusbarkeyguard = os.popen("adb shell dumpsys window policy|grep isstatusbarkeyguard | awk -f '=' ' '").read().strip('\n')

#print(isstatusbarkeyguard)

if isstatusbarkeyguard == 'true':

time.sleep(2)

print("解鎖屏保")

#左右滑動才好解鎖,並且延遲100ms啟動

os.system('adb shell input swipe 200 400 800 400 100')

time.sleep(1)

print("輸入密碼")

os.system('adb shell input text 95729')

else:

print("螢幕已解鎖不需要再次解鎖")

time.sleep(1)

mfocusedactivity = os.popen("adb shell dumpsys activity | grep 'mfocusedactivity' | awk '' | awk -f '/' ''").read().strip('\n')

if mfocusedactivity == 'com.eg.android.alipaygphone':

os.system('adb shell am force-stop com.eg.android.alipaygphone')

time.sleep(1)

os.system('adb shell am start -n com.eg.android.alipaygphone/com.eg.android.alipaygphone.alipaylogin activity')

except exception:

print("screenshot_prepare error")

traceback.print_exc()

exit(-1)

以上操作需要adb環境已經搭建好,使用以下命令檢視連線裝置

(py3env) [root@localhost alipay]# adb devices

list of devices attached

gsldu16928022488 device

adb shell dumpsys window windows |grep "current"

android 開啟 關閉ap

public class apmanager catch throwable ignored return false 關閉wifi param context public static void closewifi context context 開啟熱點 param context param...

Android使用藍芽連線adb除錯App

1.將電腦藍芽與手機進行配對 控制面板 裝置和印表機 加入裝置 2.在手機上設定 設定 很多其它無線連線 網路共享 藍芽共享網路 3.pc端,裝置和印表機 選擇配對好的手機 右鍵 連線時使用 訪問點 4.連線成功後開啟cmd查詢藍芽介面卡的ip 開啟wifi鎖 6.執行下面命令 1.su 假設前面顯...

adb開啟網頁 adb命令開啟手機設定頁面

設定主頁面 adb shell am start com.android.settings com.android.settings.settings 安全adb shell am start com.android.settings com.android.settings.securityset...