Note that there are some explanatory texts on larger screens.

plurals
  1. POGet all SharedPreferences names and all their keys?
    text
    copied!<p>I'm making backup program, that saved the phone <code>SharedPreferences</code> data into a file of my own structure. But I don't know how to list them all, which I need:</p> <p>For example, 2 program saved their SharedPreferences with names <code>"Program A"</code> and <code>"Program B"</code>. I need to obtains thay String array contain these 2 names. Then, I use <code>getSharedPreferences</code> with "Program A", I need to get all keys that program has saved.</p> <p>Is it really possible?</p> <p>EDIT1: I DON'T know what programs/activities on the phone. I want to get ALL the <code>keys</code> that every programs saved. It just like you back up all your phone data, but only SharedPreferences values. </p> <p>For example: Your phone has 10 programs, each creates a SharedPreferences named <code>Program 1</code> to <code>Program 10</code> (but of course, whatever name they want). And I would like to obtain all these <code>Program 1</code> to <code>Program 10</code> String. Then, if <code>Program 1</code> has 5 keys called <code>Key 1</code> to <code>Key 5</code>, I want to obtain these keys name.</p> <p>EDIT2: According to <code>NikolaMKD</code> guide, this is what I've done so far, but the list return all programs, with "No Preferences" at all line, even at the first, I saved the SharedPreferences with my activity:</p> <pre><code>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&lt;ResolveInfo&gt; 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 &lt; 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&lt;String&gt;(this, R.layout.main, App)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload