平台无关的 Python 封装器:Plyer
ec3y
10年前
Plyer 是一个平台无关的 Python 封装器,封装了一些平台独立的 API。Plyer 并非要重复造轮子,而是将一些平台的差异通过简单的 API 进行封装。
-
on python-for-android, pyjnius is used
-
on kivy-ios, pyobjus is used
-
on windows/mac/linux, commonly found libraries and programs will be used
示例代码:
from plyer.vibrator import vibrate vibrate(10) # in Plyer, the argument is in seconds
Support
| Platform | Android < 4.0 | Android > 4.0 | iOS | Windows | OSX | Linux |
|---|---|---|---|---|---|---|
| Accelerometer | X | X | X | | X | X |
| Camera (taking picture) | X | X | | | | |
| GPS | X | X | X | | | |
| Notifications | X | X | | X | X | X |
| Text to speech | X | X | X | X | X | X |
| Email (open mail client) | | X | X | X | X | X |
| Vibrator | X | X | | | | |
| Sms (send messages) | X | X | | | | |
| Compass | X | X | X | | | |
| Unique ID (IMEI or SN) | X | X | X | X | X | X |
| Gyroscope | X | X | X | | | |
| Battery | X | X | X | X | X | X |
| Native file chooser | | | | X | X | X |