Python: Detect Android

后端 未结 2 533
栀梦
栀梦 2021-01-16 07:29

I\'m surprised to find very little info on this topic. I want to detect if a user is running Android. I\'m using:

platform.dist()

This perf

相关标签:
2条回答
  • 2021-01-16 07:51

    You can do this with Kivy

    from kivy.utils import platform
    
    if platform == 'android':
        # do something
    

    EDIT:

    As I said, I cannot use any 3rd party libs

    Take a look at how Kivy implemented it.

    def _get_platform():
        # On Android sys.platform returns 'linux2', so prefer to check the
        # presence of python-for-android environment variables (ANDROID_ARGUMENT
        # or ANDROID_PRIVATE).
        if 'ANDROID_ARGUMENT' in environ:
            return 'android'
    
    0 讨论(0)
  • 2021-01-16 08:08

    System name is returned 'Linux' because Android is also based on the Linux Kernel.Android is the name of the distro but deep down its linux.

    0 讨论(0)
提交回复
热议问题