Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving files on external storage on Nexus 7 and retrieving from PC
    primarykey
    data
    text
    <p>For my project I want to be able to save sensor data to a file, and be able to access it from a PC for further analysis. This is the code I have so far and it works successfully:</p> <pre><code>File root = Environment.getExternalStorageDirectory(); File csvfile = new File(root, "Sensor_Data.csv"); FileWriter writer = new FileWriter(csvfile, true); writer.append("Time"); writer.append(','); writer.append("Position"); writer.append('\n'); Number data[] = new Number[4000]; for (int i = 0; i&lt;4000; i+=2){ posHistory.toArray(data); writer.append(String.valueOf(data[i])); writer.append(','); writer.append(String.valueOf(data[i+1])); writer.append('\n'); } writer.flush(); writer.close(); </code></pre> <p>The problem is that the Nexus 7 doesn't actually have external storage (I believe it uses some sort of emulator in order to be compatible with most apps which make use of external storage in their code.)</p> <p>After running this code, using Astro File manager on the device, I see a "Sensor_Data.csv" file in four locations: /sdcard, /storage/sdcard0, /storage/emulated/0, and /storage/emulated/legacy. And each of them I can open from within the device using texteditor or documentviewer and all the data is there.</p> <p>The problem is that when I connect the Nexus 7 to the PC, I only see "Internal storage" which when opened actually shows me only the virtual SD Card contents, not actual internal storage, but the .csv file isn't there. There is an additional directory "storage/emulated/legacy" but nothing in there either, and no "sdcard0" or "0" folders either. When I Log "Environment.getExternalStorageDirectory().getAbsolutePath()" to see exactly what the path is I get /storage/emulated/0</p> <p>I've tried saving the file elsewhere in internal storage with no success, but I would rather keep it in "external storage" so that the app is compatible with most devices which use external storage.</p> <p><em><strong>UPDATE</em></strong> So after using adb pull filename here are the results:</p> <pre><code>adb pull /storage/emulated/0/Sensor_Data.csv remote object '/storage/emulated/0/Sensor_Data.csv' does not exist adb pull /storage/emulated/legacy/Sensor_Data.csv 243 Kb/s &lt;1495 bytes in 0.006s&gt; adb pull /storage/sdcard0/Sensor_Data.csv 243 Kb/s &lt;1495 bytes in 0.006s&gt; adb pull /sdcard/Sensor_Data.csv 243 Kb/s &lt;1495 bytes in 0.006s&gt; </code></pre> <p>So, the only location that doesn't work is /storage/emulated/0/Sensor_Data.csv even though Astro sees it in all four and LogCat shows that it is being saved to /storage/emulated/0/</p> <p>Also just tried saving to</p> <pre><code>root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); </code></pre> <p>again I can see it in Astro in the same four locations, but when I go through Windows Explorer and navigate to the downloads folder its not there.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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