Example usage for android.app.admin DevicePolicyManager setAffiliationIds

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

Introduction

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

Prototype

public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) 

Source Link

Document

Indicates the entity that controls the device or profile owner.

Usage

From source file:com.afwsamples.testdpc.SetupManagementFragment.java

@TargetApi(Build.VERSION_CODES.O)
private void passAffiliationIds(Intent intent, PersistableBundle adminExtras) {
    ComponentName admin = DeviceAdminReceiver.getComponentName(getActivity());
    DevicePolicyManager dpm = (DevicePolicyManager) getActivity()
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
    List<String> ids = dpm.getAffiliationIds(admin);
    String affiliationId = null;/*from  www. ja v  a  2s . c om*/
    if (ids.size() == 0) {
        SecureRandom randomGenerator = new SecureRandom();
        affiliationId = Integer.toString(randomGenerator.nextInt(1000000));
        dpm.setAffiliationIds(admin, Arrays.asList(affiliationId));
    } else {
        affiliationId = ids.get(0);
    }
    adminExtras.putString(LaunchIntentUtil.EXTRA_AFFILIATION_ID, affiliationId);
}