// Capture the current state of permissions and check against the
// requirements
final ApplicationPermissionsManager apm =
ApplicationPermissionsManager.getInstance();
final ApplicationPermissions original = apm.getApplicationPermissions();
// Set up and attach a reason provider
final DemoReasonProvider drp = new DemoReasonProvider();
apm.addReasonProvider(ApplicationDescriptor
.currentApplicationDescriptor(), drp);
if (original
.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_ALLOW
&& original
.getPermission(ApplicationPermissions.PERMISSION_PHONE) == ApplicationPermissions.VALUE_ALLOW
&& original
.getPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW
&& original
.getPermission(ApplicationPermissions.PERMISSION_EMAIL) == ApplicationPermissions.VALUE_ALLOW) {
// All of the necessary permissions are currently available
return;
}
// Create a permission request for each of the permissions your
// application
// needs. Note that you do not want to list all of the possible
// permission
// values since that provides little value for the application or the
// user.
// Please only request the permissions needed for your application.
final ApplicationPermissions permRequest = new ApplicationPermissions();
permRequest
.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
permRequest.addPermission(ApplicationPermissions.PERMISSION_PHONE);
permRequest
.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
final boolean acceptance =
ApplicationPermissionsManager.getInstance()
.invokePermissionsRequest(permRequest);