I am making a backup program that saved SharedPreferences phone SharedPreferences to a file of my own structure. But I donβt know how to list them all I need:
For example, 2 programs saved their SharedPreferences with the names "Program A" and "Program B" . I need to get a thay String array containing these 2 names. Then I use getSharedPreferences with "Program A", I need to get all the keys that the program saved.
Is it possible?
EDIT1: I DON'T know what programs / actions are on the phone. I want to get ALL keys that every program will be saved. This is exactly the same as you copy all the data on your phone, but only the SharedPreferences values.
For example: your phone has 10 programs, each of which creates SharedPreferences with the name Program 1 to Program 10 (but, of course, any name they want). And I would like to get all these Program 1 to Program 10 String. Then, if Program 1 has 5 keys with the name Key 1 through Key 5 , I want to get these key names.
EDIT2: According to NikolaMKD guide, this is what I have done so far, but the list returns all programs with "No preference" on all lines, even firstly, I saved SharedPreferences with my activity
public class Test extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences preferences = getSharedPreferences("Test", 1); // No matter what name is: Test or the package name Editor editor = preferences.edit(); editor.putInt("TestKey", 0); editor.commit(); List<ResolveInfo> Temp = getPackageManager().queryIntentActivities( new Intent(Intent.ACTION_MAIN, null) .addCategory(Intent.CATEGORY_LAUNCHER), 0); String[] App = new String[Temp.size()]; for (int i = 0; i < Temp.size(); i++) { App[i] = Temp.get(i).activityInfo.name; FileReader reader = null; try { reader = new FileReader("/data/data/" + App[i] + "/shared_prefs/" + App[i] + "_preferences.xml"); } catch (FileNotFoundException e) { reader = null; } if (reader != null) App[i] += " (Have Prefereces)"; else App[i] += " (No Prefereces)"; } setListAdapter(new ArrayAdapter<String>(this, R.layout.main, App)); } }
source share