Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from jnius import autoclass
- from kivy.logger import Logger
- PythonActivity = autoclass("org.kivy.android.PythonActivity").mActivity
- Context = autoclass('android.content.Context')
- ContextCompat = autoclass('android.support.v4.content.ContextCompat')
-
-
- def check_permission(permission, activity=PythonActivity):
- permission_status = ContextCompat.checkSelfPermission(activity, permission)
- Logger.info(permission_status)
- permission_granted = 0 == permission_status
- Logger.info("Permission Status: {}".format(permission_granted))
- return permission_granted
-
- def ask_permission(permission, activity=PythonActivity):
- PythonActivity.requestPermissions([permission])
-
- Then in main:
- import Dependencies.Permissions as Permissions
- def build(self):
- self.permission_granted = Permissions.check_permission("android.permission.WRITE_EXTERNAL_STORAGE")
- if(self.permission_granted != True):
- Permissions.ask_permission("android.permission.WRITE_EXTERNAL_STORAGE")
- else:
- # do nothing, permission already granted
- return buildKV
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement