Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. //Init the SharedPreferences instance.
  2. SharedPreferences sharedPreferences = this.getApplicationContext().getSharedPreferences("com.your.package.name", Context.MODE_PRIVATE);
  3.  
  4. //Grab a map of all keys within SharedPreferences.
  5. Map<String, ?> keysMap = sharedPreferences.getAll();
  6.  
  7. /*
  8.  * 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,
  9.  * 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
  10.  * prefix to a list.
  11.  */
  12. String prefix = "PKG_STATUS";
  13. ArrayList<String> packagesList = new ArrayList<String>();
  14.  
  15. //Iterate through the Map.
  16. for (Map.Entry<String, ?> entry : keysMap.entrySet()) {
  17.     //Check if the package name starts with the prefix.
  18.     if (entry.startsWith(prefix)) {
  19.         //Add JUST the package name (trim off the prefix).
  20.         packagesList.add(entry.substring(prefix.length()));
  21.     }
  22. }
  23.  
  24. //packagesList should now contain a a list of all your packages in SharedPreferences!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement