Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Init the SharedPreferences instance.
- SharedPreferences sharedPreferences = this.getApplicationContext().getSharedPreferences("com.your.package.name", Context.MODE_PRIVATE);
- //Grab a map of all keys within SharedPreferences.
- Map<String, ?> keysMap = sharedPreferences.getAll();
- /*
- * So like I said in my previous text, you should put a prefix before your blocked apps' package names. For the sake of this example,
- * let's assume that the prefix is "PKG_STATUS". What we need to do now is iterate through keysMap and add all keys which contain the
- * prefix to a list.
- */
- String prefix = "PKG_STATUS";
- ArrayList<String> packagesList = new ArrayList<String>();
- //Iterate through the Map.
- for (Map.Entry<String, ?> entry : keysMap.entrySet()) {
- //Check if the package name starts with the prefix.
- if (entry.startsWith(prefix)) {
- //Add JUST the package name (trim off the prefix).
- packagesList.add(entry.substring(prefix.length()));
- }
- }
- //packagesList should now contain a a list of all your packages in SharedPreferences!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement