原覺得是個簡單的操做,在實踐的時候發現了一些問題。
python腳本 test.py:python
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice device = MonkeyRunner.waitForConnection() a = device.getProperty("build.device") print(a)
在cmd中運行腳本android
>>>monkeyrunner tset.py
這樣會報錯ui
LookupError: unknown encoding 'ms936'
在網上查閱一番後,緣由是編碼格式不一樣,查到的解決方案爲:
在cmd中先輸入chcp 437
而後再運行腳本編碼
上面這種方法親測可用,可是本人以爲這個須要提早在cmd中輸入的方法很難受,因而提出另外一種解決方法:
在Python 中獲取設備信息的時候轉換成string類型,就能夠正常輸出了
修改test.py 的第三行以下:操作系統
a = str(device.getProperty("build.device"))
而後再運行就能夠輸出設備名稱了。設計
經過MonkeyDevice.getProperty()方法能夠查看不少設備信息code
build.version.codename 開發代號開發
display.density 顯示邏輯密度rem
am.current.categories 當前活動的Intent指定的類別get
clock.millis 自1970年1月1日起到當前的毫秒數