in AppRestrictions/Application/src/main/java/com/example/android/apprestrictions/MainActivity.java [76:118]
protected void onResume() {
super.onResume();
// If app restrictions are set for this package, when launched from a restricted profile,
// the settings are available in the returned Bundle as key/value pairs.
Bundle restrictionsBundle = null;
final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
if (userManager != null) {
restrictionsBundle = userManager.getApplicationRestrictions(getPackageName());
}
if (restrictionsBundle == null) {
restrictionsBundle = new Bundle();
}
// Reads and displays values from a boolean type restriction entry, if available.
// An app can utilize these settings to restrict its content under a restricted profile.
final String booleanRestrictionValue =
restrictionsBundle.containsKey(GetRestrictionsReceiver.KEY_BOOLEAN) ?
restrictionsBundle.getBoolean(GetRestrictionsReceiver.KEY_BOOLEAN) + "" :
getString(R.string.na);
mBooleanEntryValue.setText(booleanRestrictionValue);
// Reads and displays values from a single choice restriction entry, if available.
final String singleChoiceRestrictionValue =
restrictionsBundle.containsKey(GetRestrictionsReceiver.KEY_CHOICE) ?
restrictionsBundle.getString(GetRestrictionsReceiver.KEY_CHOICE) :
getString(R.string.na);
mChoiceEntryValue.setText(singleChoiceRestrictionValue);
// Reads and displays values from a multi-select restriction entry, if available.
final String[] multiSelectValues =
restrictionsBundle.getStringArray(GetRestrictionsReceiver.KEY_MULTI_SELECT);
if (multiSelectValues == null || multiSelectValues.length == 0) {
mMultiEntryValue.setText(getString(R.string.na));
} else {
StringBuilder builder = new StringBuilder();
for (String value : multiSelectValues) {
builder.append(value);
builder.append(" ");
}
mMultiEntryValue.setText(builder.toString());
}
}