Skip to Content
defold-typescript libraries
defold (official)

defold/extension-permissions/permissions

Functions and constants for interacting with permissions related APIs

  • GitHub: defold/extension-permissions — pinned to 1.1.1 (released while Defold 1.13.1 was current)
    1. Pick a release from defold/extension-permissions releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as permissions from "permissions"

Functions

permissions.check(permission: string): number

Determine whether you have been granted a particular permission.

local result = permissions.check("android.permission.ACCESS_NETWORK_STATE")
if result == permissions.PERMISSION_DENIED then
    -- You can directly ask for the permission.
elseif result == permissions.PERMISSION_GRANTED then
    -- You can use the API that requires the permission.
elseif result == permissions.PERMISSION_SHOW_RATIONALE then
    -- In an educational UI, explain to the user why your app requires this
    -- permission for a specific feature to behave as expected, and what
    -- features are disabled if it's declined. In this UI, include a
    -- "cancel" or "no thanks" button that lets the user continue
    -- using your app without granting the permission.
end

Parameters

  • permission: string — A constant that represent permission, for example android.permission.ACCESS_NETWORK_STATE

Returns

  • result: number — A result can be one of the predefined constants below
    • permissions.PERMISSION_GRANTED
    • permissions.PERMISSION_DENIED
    • permissions.PERMISSION_SHOW_RATIONALE

permissions.request(request_tbl: table, callback: function)

Requests permissions to be granted to this application.

local permissions_table = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_CONTACTS"}
permissions.request(permissions_table,
    function(self, result)
        for permission, result in pairs(result) do
          if result == permissions.PERMISSION_DENIED then
              -- You can directly ask for the permission.
          elseif result == permissions.PERMISSION_GRANTED then
              -- You can use the API that requires the permission.
          elseif result == permissions.PERMISSION_SHOW_RATIONALE then
              -- In an educational UI, explain to the user why your app requires this
              -- permission for a specific feature to behave as expected, and what
              -- features are disabled if it's declined. In this UI, include a
              -- "cancel" or "no thanks" button that lets the user continue
              -- using your app without granting the permission.
          end
        end
    end)

Parameters

  • request_tbl: table — An array with constants that represent permissions.
  • callback: function — A callback taking the following parameters
    • self: object — The calling script
    • result: table — A table where key is permission string and key is one of the following constants
      • permissions.PERMISSION_GRANTED
      • permissions.PERMISSION_DENIED

Constants

permissions.PERMISSION_GRANTED

The permission has been granted to the given package.

permissions.PERMISSION_DENIED

The permission has not been granted to the given package.

permissions.PERMISSION_SHOW_RATIONALE

Explain why your app needs the permission Android doc

On this page