From 9ca72034b546b5bcfecaf32e326ada5f9cd882fd Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 12 Mar 2022 14:12:46 +0100 Subject: [PATCH] Use sys.getandroidapilevel for more robust Android detection --- plyer/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plyer/utils.py b/plyer/utils.py index 1862e0677..101763e97 100644 --- a/plyer/utils.py +++ b/plyer/utils.py @@ -8,6 +8,7 @@ from os import environ from os import path from sys import platform as _sys_platform +import sys class Platform: @@ -41,9 +42,11 @@ def __hash__(self): def _get_platform(self): if self._platform_android is None: + # sys.getandroidapilevel is defined as of Python 3.7 # ANDROID_ARGUMENT and ANDROID_PRIVATE are 2 environment variables # from python-for-android project - self._platform_android = 'ANDROID_ARGUMENT' in environ + self._platform_android = hasattr(sys, 'getandroidapilevel') or \ + 'ANDROID_ARGUMENT' in environ if self._platform_ios is None: self._platform_ios = (environ.get('KIVY_BUILD', '') == 'ios')