How to distinguish "Android" from other "Linux" operating systems in Python?

I am running a Python script on my phone via QPython. The title pretty much explains the question. Basically I need to check if a script is running on an android device. I tried os.name

, sys.platform

and platform.system()

, but they just return different types of "Linux" or "Posix", which is not specific enough (as far as I know - I may be missing some important information here).

I decided to try importing the module android

and then use success or failure to determine if the OS is Android. I don't really need the module android

, so this seems a bit over the top.

+3


source to share


1 answer


You can check 'ANDROID_STORAGE'

in the environment:



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

      

+3


source







All Articles