3

I am trying to make a library/module for my project which will show all of the SharedPreferences of an application.

One way to get all the SharedPreferences is:

Map<String,?> keys = prefs.getAll();  // app sharedPreference

for(Map.Entry<String,?> entry : keys.entrySet()){
    Log.d("map values",entry.getKey() + ": " + entry.getValue().toString()); 
}

Now I am trying to get all preferences of an application without knowing the application preferences.

Map<String,?> keys = prefs.getAll(); // app sharedPreference (without knowing prefs)

Is this possible?

Daniel
  • 2,355
  • 9
  • 23
  • 30
Harsh Shah
  • 2,162
  • 2
  • 19
  • 39

1 Answers1

0

Well, it should work, if anything is there... Just tested the following, and got nothing in return.

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Map<String,?> keys = prefs.getAll();  // app sharedPreference

Log.d("- Starting -", "Printing");
for(Map.Entry<String,?> entry : keys.entrySet()){
    Log.d("map values",entry.getKey() + ": " + entry.getValue().toString());
}
Log.d("--- End ---", "Printing");

What I use myself to store sharedPreffs is something like the following. And if some ones uses that, you are going to have a very hard time, if not impossible to get the data from it.

context.getSharedPreferences(SETTINGS_FILE, Context.MODE_PRIVATE);

For more information and good use of sharedPreferences please look here.

Community
  • 1
  • 1