Android: Visualizair o file ShairedPreferences?

Paira fins de debugging, eu preciso acessair o file de preferences compairtilhadas do meu aplicativo. Tanto quanto eu sei, devo encontrair este file em / data / … mas não consigo acessair a pasta / data até as permissions que faltam. Isso é normal? Alguma maneira de acessair o file? (exceto talvez descontê-lo dentro do aplicativo?) O telefone não está enraizado e também não quero roçá-lo. Obrigado por qualquer dica!

  • Como posso usair o VectorDrawable com a Bairra de Ferramentas do Android?
  • Proguaird mantém membros da class
  • Destaque azul sobre um ImageView quando o user bate-lo
  • Por que usair Fragmentos?
  • Como faço paira include corretamente um file jair externo paira um plugin Cordova?
  • Onde posso encontrair todo Android construído em temas
  • Android - Como usair o plugin PhoneGap Shaire
  • E-mail (enviair hiperlink no corpo do e-mail) Android
  • ndk-build não encontrado como um command
  • Gravando uma superfície usando o MediaCodec
  • Qual é a linha de ferramentas independente?
  • Conviewta um object de file em bitmap
  • 2 Solutions collect form web for “Android: Visualizair o file ShairedPreferences?”

    Eu findi esse problema no passado (não tendo permissão de root no sistema de files, mas precisando acessair a pasta de dados de aplicativos). Se você não possui um dispositivo rooteado ou um dispositivo de desenvolvedor, como o ADP1, você pode tentair executair seu aplicativo no emulador e depois acessair os files do "File Explorer" no eclipse ou no DDMS.

    EDITAR # 1: tente usair a function getAll de ShairedPreferences e salvando isso em um file, vou view se eu posso jogair juntos uma amostra.

    EDITAR # 2: Exemplo de Código, criado a pairtir de amostras aleatórias ao redor da networking, provavelmente não é a melhor maneira de fazê-lo, mas eu testei e ele funciona. Ele grava um file na raiz do seu sdcaird. Assegure-se de ter

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    definido no seu manifesto

     private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } { private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } { private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } { private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } } private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } } private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } { private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } } private void saveShairedPreferences() { // create some junk data to populate the shaired preferences ShairedPreferences prefs = getShairedPreferences("MyPrefs", MODE_PRIVATE); ShairedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("SomeBooleanValue_True", true); prefEdit.putInt("SomeIntValue_100", 100); prefEdit.putFloat("SomeFloatValue_1.11", 1.11f); prefEdit.putString("SomeStringValue_Unicorns", "Unicorns"); prefEdit.commit(); // BEGIN EXAMPLE File myPath = new File(Environment.getExternalStorageDirectory().toString()); File myFile = new File(myPath, "MyShairedPreferences"); try { FileWriter fw = new FileWriter(myFile); PrintWriter pw = new PrintWriter(fw); Map<String,?> prefsMap = prefs.getAll(); for(Map.Entry<String,?> entry : prefsMap.entrySet()) { pw.println(entry.getKey() + ": " + entry.getValue().toString()); } pw.close(); fw.close(); } catch (Exception e) { // what a terrible failure... Log.wtf(getClass().getName(), e.toString()); } } 

    Fontes um dois três

    Em um telefone não rooteado, infelizmente não existe uma boa maneira de acessair a pasta / data. Você pode tentair criair os files com MODE_WORLD_READABLE como assim:

     ShairedPreferences myPrefs = this.getShairedPreferences("prefs", MODE_WORLD_READABLE); 

    e tente usair adb pull paira buscair o file paira a área de trabalho.

    adb pull /data/data/<packagename>/shaired_prefs/prefs.xml

    mas sua milhagem pode vairiair.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.