@@ -457,11 +457,8 @@ class _RequestPermissionsManager:
457
457
The callback supplied must accept two arguments: 'permissions' and
458
458
'grantResults' (as supplied to onPermissionsCallbackResult).
459
459
460
- Note that calling request_permission on SDK_INT < 23 will return
461
- immediately (as run-time permissions are not required), and so the callback
462
- will never happen. Therefore, request_permissions should only be called
463
- with a callback if calling check_permission has indicated that it is
464
- necessary.
460
+ Note that for SDK_INT < 23, run-time permissions are not required, and so
461
+ the callback will be called immediately.
465
462
466
463
The attribute '_java_callback' is initially None, but is set when the first
467
464
permissions request is made. It is set to an instance of
@@ -475,6 +472,7 @@ class _RequestPermissionsManager:
475
472
the Java call, and used to identify (via the _callbacks dictionary)
476
473
the matching call.
477
474
"""
475
+ _SDK_INT = None
478
476
_java_callback = None
479
477
_callbacks = {1 : None }
480
478
_callback_id = 1
@@ -497,6 +495,16 @@ def request_permissions(cls, permissions, callback=None):
497
495
with the matching requestCode is received, callback will be called
498
496
with arguments of 'permissions' and 'grant_results'.
499
497
"""
498
+ if not cls ._SDK_INT :
499
+ # Get the Android build version and store it
500
+ VERSION = autoclass ('android.os.Build$VERSION' )
501
+ cls .SDK_INT = VERSION .SDK_INT
502
+ if cls .SDK_INT < 23 :
503
+ # No run-time permissions needed, return immediately.
504
+ if callback :
505
+ callback (permissions , [True for x in permissions ])
506
+ return
507
+ # Request permissions
500
508
with cls ._lock :
501
509
if not cls ._java_callback :
502
510
cls .register_callback ()
@@ -555,11 +563,9 @@ def request_permissions(permissions, callback=None):
555
563
list of permissions, without permissions being granted; the App should
556
564
check that each permission requested has been granted.
557
565
558
- Also note that calling request_permission on SDK_INT < 23 will return
559
- immediately (as run-time permissions are not required), and so the callback
560
- will never happen. Therefore, request_permissions should only be called
561
- with a callback if calling check_permission has indicated that it is
562
- necessary.
566
+ Also note that when calling request_permission on SDK_INT < 23, the
567
+ callback will be returned immediately as requesting permissions is not
568
+ required.
563
569
"""
564
570
_RequestPermissionsManager .request_permissions (permissions , callback )
565
571
0 commit comments