From f37944623025f7e1466bbb1f6fbb142e718cfa51 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Mon, 10 May 2021 19:56:27 +0300 Subject: [PATCH] Handle checkPermission() below api 23 Although Qt 6 supports API 23+, it's still not bad to do this fix, it achieves two things: * Avoid the use of reflection when checking for permission state * It works for all api versions With this we would be sure we don't need to do a check in c++ if (androidSdkVersion < 23) return true; The platform api checks if permission is granted or not, irrelevant of the api version. Change-Id: I9766dc35bbc8347ad0d60fde54b95710c8866736 Reviewed-by: Alex Blasche --- .../jar/src/org/qtproject/qt/android/QtNative.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtNative.java b/src/android/jar/src/org/qtproject/qt/android/QtNative.java index f9bb680cb6..5529cbdf62 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -843,13 +843,8 @@ public class QtNative int perm = PackageManager.PERMISSION_DENIED; synchronized (m_mainActivityMutex) { Context context = getContext(); - try { - if (m_checkSelfPermissionMethod == null) - m_checkSelfPermissionMethod = Context.class.getMethod("checkSelfPermission", String.class); - perm = (Integer)m_checkSelfPermissionMethod.invoke(context, permission); - } catch (Exception e) { - e.printStackTrace(); - } + PackageManager pm = context.getPackageManager(); + perm = pm.checkPermission(permission, context.getPackageName()); } return perm;