Skip to content

Requests runtime permissions list, fixes #1704 #1741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/apis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ to access the SD card, the camera, and other things.
This can be done through the `android` module which is *available per default*
unless you blacklist it. Use it in your app like this::

from android.permissions import request_permission, Permission
request_permission(Permission.WRITE_EXTERNAL_STORAGE)
from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

The available permissions are listed here:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,16 @@ public boolean checkCurrentPermission(String permission) {
}

/**
* Used by android.permissions p4a module to request a permission
* Used by android.permissions p4a module to request runtime permissions
**/
public void requestNewPermission(String permission) {
public void requestPermissions(String[] permissions) {
if (android.os.Build.VERSION.SDK_INT < 23)
return;

try {
java.lang.reflect.Method methodRequestPermission =
Activity.class.getMethod("requestPermissions",
java.lang.String[].class, int.class);
methodRequestPermission.invoke(this, new String[] {permission}, 1);
methodRequestPermission.invoke(this, permissions, 1);
} catch (IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
}
Expand Down
8 changes: 6 additions & 2 deletions pythonforandroid/recipes/android/src/android/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,13 @@ class Permission:
)


def request_permission(permission):
def request_permissions(permissions):
python_activity = autoclass('org.kivy.android.PythonActivity')
python_activity.requestNewPermission(permission + "")
python_activity.requestPermissions(permissions)


def request_permission(permission):
request_permissions([permission])


def check_permission(permission):
Expand Down
4 changes: 3 additions & 1 deletion pythonforandroid/recipes/pyjnius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


class PyjniusRecipe(CythonRecipe):
version = '1.1.3'
# "6553ad4" is one commit after last release (1.2.0)
# it fixes method resolution, required for resolving requestPermissions()
version = '6553ad4'
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
name = 'pyjnius'
depends = [('genericndkbuild', 'sdl2', 'sdl'), 'six']
Expand Down