Advertisement
DarKnighTitan

Untitled

Feb 1st, 2021
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. from jnius import autoclass
  2.  
  3. from kivy.logger import Logger
  4.  
  5. PythonActivity = autoclass("org.kivy.android.PythonActivity").mActivity
  6.  
  7. Context = autoclass('android.content.Context')
  8.  
  9. ContextCompat = autoclass('android.support.v4.content.ContextCompat')
  10.  
  11.  
  12.  
  13. def check_permission(permission, activity=PythonActivity):
  14.  
  15. permission_status = ContextCompat.checkSelfPermission(activity, permission)
  16.  
  17. Logger.info(permission_status)
  18.  
  19. permission_granted = 0 == permission_status
  20.  
  21. Logger.info("Permission Status: {}".format(permission_granted))
  22.  
  23. return permission_granted
  24.  
  25.  
  26. def ask_permission(permission, activity=PythonActivity):
  27.  
  28. PythonActivity.requestPermissions([permission])
  29.  
  30.  
  31. Then in main:
  32.  
  33. import Dependencies.Permissions as Permissions
  34.  
  35. def build(self):
  36.  
  37. self.permission_granted = Permissions.check_permission("android.permission.WRITE_EXTERNAL_STORAGE")
  38.  
  39. if(self.permission_granted != True):
  40.  
  41. Permissions.ask_permission("android.permission.WRITE_EXTERNAL_STORAGE")
  42.  
  43. else:
  44.  
  45. # do nothing, permission already granted
  46.  
  47. return buildKV
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement