保存在Nexus 7上的外部存储的文件和电脑检索存在、文件、电脑、Nexus

2023-09-13 01:38:00 作者:游戏个性名字,有个性的网络游戏名

有关我的项目,我希望能够给传感器数据保存到文件中,并能够从PC访问它作进一步的分析。这是code我有这么远,它的工作原理成功:

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:

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<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();

问题是,Nexus的7实际上没有外部存储(我相信它使用某种形式的仿真器,以便与大多数应用程序而使用外部存储在自己的code兼容的。)

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.)

运行此code,使用天文文件管理设备后,我看到一个Sensor_Data.csv文件中的四个位置:/ SD卡,/存储/ sdcard0,/存储/模拟/ 0,和/存储/模拟/遗产。他们每个人我可以使用文本编辑或的DocumentViewer所有的数据在设备内打开是存在的。

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.

现在的问题是,当我了Nexus 7连接到PC,我只看到内部存储,它打开时,居然显示我只是虚拟SD卡的内容,而不是实际的内部存储,但.csv文件是不是那里。还有一个额外的目录存储/模拟/遗产,但没有在那里任,并没有sdcard0或0的文件夹无论是。当我登录Environment.getExternalStorageDirectory()。getAbsolutePath(),看看究竟的路径是什么,我获得/存储/模拟/ 0

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

我已经试过在内部存储在别处保存该文件没有成功,但我宁愿保持在外部存储这样的应用程序是与使用外部存储大多数设备兼容。

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.

更新的 因此,使用亚行拉文件名后,这里的结果:

UPDATE So after using adb pull filename here are the results:

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 <1495 bytes in 0.006s>

adb pull /storage/sdcard0/Sensor_Data.csv
243 Kb/s <1495 bytes in 0.006s>

adb pull /sdcard/Sensor_Data.csv
243 Kb/s <1495 bytes in 0.006s>

所以,不工作的唯一位置就是/storage/emulated/0/Sensor_Data.csv即使天文看到它在所有四个LogCat中表明,它被保存到/存储/模拟/ 0 /

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/

也只是试图保存到

root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

我又可以看到它在Astro在相同的四个位置,但是当我通过Windows资源管理器,然后导航到下载文件夹它不存在。

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.

推荐答案

为什么,最好不要将它发送给你的邮件。请看下面的例子:

Why, best not to send it to your mail. See the following example:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
    Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
    finish();
    return;
}
Uri uri = Uri.parse("file://" + file.getAbsolutePath());
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));
 
精彩推荐
图片推荐