小白学 Python操控手机APP攻略2
泛域名ssl证书 239元1年送1个月、单域名39元1年,Sectigo(原Comodo证书)全球可信证书,强大的兼容性,高度安全性,如有问题7天内可退、可开发票
加微信VX 18718058521 备注SSL证书
【腾讯云】2核2G4M云服务器新老同享99元/年,续费同价
https://developer.android.google.cn/studio/command-line/adb
1. Android SDK下载和配置
adb tcpid 5555
adb connect xxx.xxx.xxx.xxx(手机ip)
adb server version (36) doesn't match this client (40); killing...,
➜ adb devicesList of devices attached127.0.0.1:62001 device
2. ADB的一些基本操作
1).显示所有包名
adb shell pm list packages
➜ adb shell pm list package -3package:io.appium.settingspackage:com.example.android.contactmanagerpackage:com.kugou.android
2).显示活动程序
adb shell dumpsys activity activities
➜ ~ adb shell dumpsys activity activitiesRunning activities (most recent first):TaskRecord{4a9fe700 #2 A=android.task.kugou U=0 sz=1}Run #0: ActivityRecord{4a96e0c8 u0 com.kugou.android/.app.MediaActivity t2}mResumedActivity: ActivityRecord{4a96e0c8 u0 com.kugou.android/.app.MediaActivity t2}mLastPausedActivity: ActivityRecord{4a921424 u0 com.kugou.android/.app.splash.SplashActivity t2 f}mFocusedActivity: ActivityRecord{4a96e0c8 u0 com.kugou.android/.app.MediaActivity t2}mDismissKeyguardOnNextActivity=falsemFocusedStack=ActivityStack{4a9e1488 stackId=1, 1 tasks} mStackState=STACK_STATE_HOME_IN_BACKRecent tasks:* Recent #0: TaskRecord{4a9fe700 #2 A=android.task.kugou U=0 sz=1}numActivities=1 rootWasReset=true userId=0 mTaskType=0 numFullscreen=1 mOnTopOfHome=trueaffinity=android.task.kugouintent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.kugou.android/.app.splash.SplashActivity}realActivity=com.kugou.android/.app.splash.SplashActivityActivities=[ActivityRecord{4a96e0c8 u0 com.kugou.android/.app.MediaActivity t2}]askedCompatMode=falselastThumbnail=null lastDescription=null lastActiveTime=446142 (inactive for 13s)
adb shell dumpsys activity | grep mFocusedActivity
3).启动应用程序
adb shell am start -n 要启动的应用Activity名称
adb shell am start -n com.kugou.android/.app.splash.SplashActivity
adb shell am start -n com.kugou.android
4).停止应用程序
adb shell am force-stop 要停止的应用名称
adb shell am force-stop com.kugou.android
5).点击指定位置
adb shell input tap x y
6).滑动手机屏幕
adb shell input swipe x_start y_start x_end y_end
7).输入文字信息
adb shell input text 需要输入的字符
8).模拟手机按键
adb shell input keyevent code
https://developer.android.google.cn/reference/android/view/KeyEvent
9).获取元素位置
https://developer.android.google.cn/studio/command-line/adb?hl=zh_cn
3. Python操作手机App
```pythondef execute(cmd):adb_str="adb shell {}".format(cmd)print(adb_str)os.system(adb_str)if __name__ == '__main__':execute("am start -n com.kugou.android/.app.splash.SplashActivity")time.sleep(3)execute("input tap 263 515")```