Python:检测Android [英] Python: Detect Android

查看:42
本文介绍了Python:检测Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶地发现关于该主题的信息很少.我想检测用户是否正在运行Android.我正在使用:

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()

这可以完美检测所有操作系统和不同的Linux发行版.但是,在Android上运行时,系统名称始终以"Linux"返回.有什么方法可以检测Android吗?我不想包含任何第3方模块,因为它必须尽可能地可移植.也许我可以在try-catch中调用某些特定的Android函数?

This perfectly detects all all OSs and different Linux distros. However, when running this on Android, it system name is always returned as "Linux". Is there any way to detect Android? I do not want to include any 3rd party modules, since this has to be as portable as possible. Is there maybe some specific Android function that I can call in a try-catch?

推荐答案

您可以使用

正如我所说,我不能使用任何第三方库

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

看看Kivy是如何实现的

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'

这篇关于Python:检测Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆