Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
builder and asfdfdfd Initial commit
Latest commit ab941f8 May 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android_permissions Initial commit May 14, 2019
input Initial commit May 14, 2019
main Initial commit May 14, 2019
manifests/android Initial commit May 14, 2019
.gitignore Initial commit May 14, 2019
LICENSE.txt Initial commit May 14, 2019
README.rst Initial commit May 14, 2019
game.project Initial commit May 14, 2019

README.rst

Defold Android Permissions

This is Native Extension for the Defold Game Engine that adds support for Android Runtime Permissions.

Become a Patron!

Setup

You can use extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add https://github.com/asfdfdfd/defold-android-permissions/archive/master.zip or point to the ZIP file of a specific release.

Implementation details

Before requesting permissions you have to add them to the AndroidManifest.xml.

If you are working on cross-platform application the best practice is to check the existence of android_permissions module, this module exists only in android bundle:

if android_permissions then
  -- call android_permissions methods
end

API

android_permissions.is_permission_granted(permission)

Returns 'true' if permission is granted.

android_permissions.is_permission_granted("android.permission.READ_CONTACTS")

android_permissions.request_permissions(permissions, callback_function)

Requests permissions from user and returns result dictionary in 'callback_function'. Dictionary key is permission name, dictionary value is 'android_permissions.PERMISSION_GRANTED' if permission request is granted, 'android_permissions.PERMISSION_DENIED' if permission request is denied and 0 if permission request is cancelled.

local permissions = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_CONTACTS"}

android_permissions.request_permissions(permissions, function (results)
    for permission, grant_result in pairs(results) do
        if grant_result == android_permissions.PERMISSION_GRANTED then
            -- do something.
        elseif grant_result == android_permissions.PERMISSION_DENIED then
            -- do something.
        end
    end
end)

android_permissions.should_show_request_permission_rationale(permission)

Checks whether you should show UI with rationale for requesting a permission. You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.

Returns 'true' if application should show rationale.

android_permissions.should_show_request_permission_rationale("android.permission.READ_CONTACTS")
You can’t perform that action at this time.