简体   繁体   English

如何在Python中区分“Android”与其他“Linux”操作系统?

[英]How to distinguish “Android” from other “Linux” operating systems in Python?

I'm running a Python script on my phone through QPython. 我正通过QPython在手机上运行Python脚本。 The title pretty much explains the question. 标题几乎解释了这个问题。 I basically need to check if the script is running on an android device. 我基本上需要检查脚本是否在Android设备上运行。 I've tried os.name , sys.platform and platform.system() but those just return various kinds of "Linux" or "Posix", which is not specific enough (as far as I know - maybe I am missing some relevant information here). 我已经尝试过os.namesys.platformplatform.system()但是那些只返回各种“Linux”或“Posix”,这些不够具体(据我所知 - 也许我错过了一些相关的这里的信息)。

I considered trying to import the android module, and then use the success or failure of this to determine if the OS is Android. 我考虑过尝试导入android模块,然后使用它的成功或失败来确定操作系统是否是Android。 I don't really need the android module though, so this seems a bit excessive. 我不是真的需要android模块,所以这似乎有点过分。

You can check for 'ANDROID_STORAGE' in environ: 您可以在environ中检查'ANDROID_STORAGE'

>>> from os import environ
>>> is_android = 'ANDROID_STORAGE' in environ
>>> is_android
True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OpenCV支持哪些Android操作系统? - Which Android Operating Systems are supported by OpenCV? psutil 可以和安卓操作系统一起使用吗 - Could psutil used with android operating systems 如何区分在 Android 和传统 Linux 上运行的 ELF 文件? - How to distinguish ELF files running on Android and on traditional Linux? 支持android,ios和blackberry操作系统的默认字体列表 - Default list of fonts which supports android,ios and blackberry operating systems 如何区分谷歌玻璃与其他蓝牙设备? - How to distinguish google glass from other bluetooth devices? 如何为多种不同的设备和操作系统设计 React Native - How to style react native for multiple different devices and operating systems 如何区分Android Web视图和浏览器视图? - How to distinguish android web view from browser view? 如何区分图像是来自Android中的图库还是来自相机? - How to distinguish whether the image is coming from gallery or camera in android? 将生产的Android应用正确地从Windows 7移动/移植到基于Linux的系统 - Moving/Porting Production Android Apps from Windows 7 to Linux Based Systems Correctly 如何在Android中区分布局文件夹? - how to distinguish layout folder in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM