cordova-plugin-permission
v0.1.0
Published
Verify and request grants for Android app permissions
Downloads
415
Maintainers
Readme
cordova-plugin-permission
This plugin provides the ability to verify and request grants for Android app permissions.
Installation
cordova plugin add cordova-plugin-permission
Supported platforms
- Android
Usage
var Permission = window.plugins.Permission
var permission = 'android.permission.RECORD_AUDIO'
Permission.has(permission, function(results) {
if (!results[permission]) {
Permission.request(permission, function(results) {
if (result[permission]) {
// permission is granted
}
}, alert)
}
}, alert)
API
Modules
Typedefs
Permission
Permission.has(permissions, successCallback, errorCallback)
Asynchronously returns an object indicating whether given permissions are granted.
Kind: static method of Permission
| Param | Type | Description | | --- | --- | --- | | permissions | String | Array.<String> | A permission or an array of permissions. | | successCallback | successCallback | | | errorCallback | errorCallback | |
Example
var Permission = window.plugins.Permission
// verify grant for a permission
var permission = 'android.permission.RECORD_AUDIO'
Permission.has(permission, function(results) {
if (results[permission]) {
// permission is granted
}
}, alert)
// verify grant for multiple permissions
var permissions = ['android.permission.RECORD_AUDIO', 'android.permission.READ_CONTACTS']
Permission.has(permissions, function(results) {
if (results['android.permission.RECORD_AUDIO']) {
// permission is granted
}
}, alert)
Permission.request(permissions, successCallback, errorCallback)
Requests permissions and asynchronously returns an object indicating whether given permissions are granted.
Kind: static method of Permission
| Param | Type | Description | | --- | --- | --- | | permissions | String | Array.<String> | A permission or an array of permissions. | | successCallback | successCallback | | | errorCallback | errorCallback | |
Example
var Permission = window.plugins.Permission
// request grant for a permission
var permission = 'android.permission.RECORD_AUDIO'
Permission.request(permission, function(results) {
if (results[permission]) {
// permission is granted
}
}, alert)
// request grant for multiple permissions
var permissions = ['android.permission.RECORD_AUDIO', 'android.permission.READ_CONTACTS']
Permission.request(permissions, function(results) {
if (results['android.permission.RECORD_AUDIO']) {
// permission is granted
}
}, alert)
successCallback : function
Kind: global typedef
| Param | Type | Description | | --- | --- | --- | | results | Object.<String, Boolean> | Each property of the object is a string indicating an app permission. Each value is a boolean indicating whether the app permission is granted. |
errorCallback : function
Kind: global typedef
| Param | Type | | --- | --- | | err | Error |
License
This project is MIT-licensed