Example usage for android.app.admin DevicePolicyManager getAffiliationIds

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

Introduction

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

Prototype

public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) 

Source Link

Document

Returns the set of affiliation ids previously set via #setAffiliationIds , or an empty set if none have been set.

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;/*  ww  w .  jav a  2  s. co m*/
    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);
}