List of usage examples for android.content RestrictionsManager getManifestRestrictions
public List<RestrictionEntry> getManifestRestrictions(String packageName)
From source file:com.example.android.apprestrictionschema.AppRestrictionSchemaFragment.java
private void resolveRestrictions() { RestrictionsManager manager = (RestrictionsManager) getActivity() .getSystemService(Context.RESTRICTIONS_SERVICE); Bundle restrictions = manager.getApplicationRestrictions(); List<RestrictionEntry> entries = manager .getManifestRestrictions(getActivity().getApplicationContext().getPackageName()); for (RestrictionEntry entry : entries) { String key = entry.getKey(); Log.d(TAG, "key: " + key); if (key.equals(KEY_CAN_SAY_HELLO)) { updateCanSayHello(entry, restrictions); } else if (key.equals(KEY_MESSAGE)) { updateMessage(entry, restrictions); } else if (key.equals(KEY_NUMBER)) { updateNumber(entry, restrictions); } else if (key.equals(KEY_RANK)) { updateRank(entry, restrictions); } else if (key.equals(KEY_APPROVALS)) { updateApprovals(entry, restrictions); } else if (key.equals(KEY_ITEMS)) { updateItems(restrictions);/* w ww. jav a 2 s . c o m*/ } } }
From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java
/** * Loads the restrictions for the AppRestrictionSchema sample. * * @param activity The activity//from w ww. j ava2 s .co m */ private void loadRestrictions(Activity activity) { RestrictionsManager manager = (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE); List<RestrictionEntry> restrictions = manager .getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA); SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); for (RestrictionEntry restriction : restrictions) { String key = restriction.getKey(); if (RESTRICTION_KEY_SAY_HELLO.equals(key)) { updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO, restriction.getSelectedState())); } else if (RESTRICTION_KEY_MESSAGE.equals(key)) { updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE, restriction.getSelectedString())); } else if (RESTRICTION_KEY_NUMBER.equals(key)) { updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER, restriction.getIntValue())); } else if (RESTRICTION_KEY_RANK.equals(key)) { updateRank(activity, restriction.getChoiceValues(), prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString())); } else if (RESTRICTION_KEY_APPROVALS.equals(key)) { updateApprovals(activity, restriction.getChoiceValues(), TextUtils.split( prefs.getString(RESTRICTION_KEY_APPROVALS, TextUtils.join(DELIMETER, restriction.getAllSelectedStrings())), DELIMETER)); } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) { String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, ""); HashMap<String, String> items = new HashMap<>(); for (String itemString : TextUtils.split(itemsString, DELIMETER)) { String[] strings = itemString.split(SEPARATOR, 2); items.put(strings[0], strings[1]); } updateItems(activity, items); } } }