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