Example usage for android.app.admin DevicePolicyManager PERMISSION_POLICY_PROMPT

List of usage examples for android.app.admin DevicePolicyManager PERMISSION_POLICY_PROMPT

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager PERMISSION_POLICY_PROMPT.

Prototype

int PERMISSION_POLICY_PROMPT

To view the source code for android.app.admin DevicePolicyManager PERMISSION_POLICY_PROMPT.

Click Source Link

Document

Permission policy to prompt user for new permission requests for runtime permissions.

Usage

From source file:org.wso2.iot.agent.services.PolicyRevokeHandler.java

@RequiresApi(api = Build.VERSION_CODES.M)
private void revokeRunTimePermissionPolicyOperation(Operation operation) throws AndroidAgentException {
    if (devicePolicyManager.isDeviceOwnerApp(Constants.AGENT_PACKAGE)
            || devicePolicyManager.isProfileOwnerApp(Constants.AGENT_PACKAGE)) {
        devicePolicyManager.setPermissionPolicy(deviceAdmin, DevicePolicyManager.PERMISSION_POLICY_PROMPT);
        Preference.putString(context, Constants.RuntimePermissionPolicy.PERMITTED_APP_DATA, "");
    }/*from   w  w w .j  av  a2 s  . c o m*/
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Shows the default response for future runtime permission requests by applications, and lets
 * the user change the default value.//from   w  w  w  . jav  a2  s  .c o m
 */
@TargetApi(Build.VERSION_CODES.M)
private void showSetPermissionPolicyDialog() {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }
    View setPermissionPolicyView = getActivity().getLayoutInflater().inflate(R.layout.set_permission_policy,
            null);
    final RadioGroup permissionGroup = (RadioGroup) setPermissionPolicyView
            .findViewById(R.id.set_permission_group);

    int permissionPolicy = mDevicePolicyManager.getPermissionPolicy(mAdminComponentName);
    switch (permissionPolicy) {
    case DevicePolicyManager.PERMISSION_POLICY_PROMPT:
        ((RadioButton) permissionGroup.findViewById(R.id.prompt)).toggle();
        break;
    case DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT:
        ((RadioButton) permissionGroup.findViewById(R.id.accept)).toggle();
        break;
    case DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY:
        ((RadioButton) permissionGroup.findViewById(R.id.deny)).toggle();
        break;
    }

    new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.set_default_permission_policy))
            .setView(setPermissionPolicyView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int policy = 0;
                    int checked = permissionGroup.getCheckedRadioButtonId();
                    switch (checked) {
                    case (R.id.prompt):
                        policy = DevicePolicyManager.PERMISSION_POLICY_PROMPT;
                        break;
                    case (R.id.accept):
                        policy = DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT;
                        break;
                    case (R.id.deny):
                        policy = DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY;
                        break;
                    }
                    mDevicePolicyManager.setPermissionPolicy(mAdminComponentName, policy);
                    dialog.dismiss();
                }
            }).show();
}