List of usage examples for android.app.admin DevicePolicyManager getAffiliationIds
public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin)
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); }