[无法在PC上访问文件夹:1:https://i.stack.imgur.com/FuKdy.png]
我想将传感器数据保存到外部存储器中的公用文件夹中。因此,该文件夹仅可见,但无法通过PC进行访问,如随附的图像所示。在Android上,我可以毫无问题地访问数据。
我真的不知道问题,因为我已经授予了外部存储的权限,尝试了“ ExternalStorageDirectory”和“ ExternalStoragePublicDirectory”,并在FileWriters关闭后添加了MediaScanner。此外,我以两种不同的方式尝试了MediaScanner:一次,它扫描了文件夹,一次,它扫描了传感器文件。什么都没用。
因此,如果您能给我一个提示,为什么我无法通过PC访问该文件夹,我将非常感谢。提前非常感谢您!
总结-我已经尝试过了: -外部存储目录 -ExternalStoragePublicDirectory -MediaScanner扫描文件 -MediaScanner扫描文件夹 -我也尝试遵循以下问题:Saving public files in android but folders are not accessible by PC
FileWriter GPSwriter;
File f;
//Check if external storage is available
private boolean isExternalStorageWritable(){
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
Log.i("state", "Yes, it is writable");
return true;
} else {
return false;
}
//Create Folder
myfolder = "Logger";
f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), myfolder);
f.setExecutable(true);
f.setReadable(true);
f.setWritable(true);
if (!f.exists()) {
f.mkdirs()
} else {
Toast.makeText(getApplicationContext(), "Pfad " + myfolder + " existiert bereits", Toast.LENGTH_LONG).show();
}
//Filewriter
GPSwriter.write(String.format(Locale.ENGLISH, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d\n", curGPStime, curLat, curLong, curAlt, curSpeed, curBearing, curHorzAcc, curBearAcc, curSpeedAcc, curVertAcc, curElaTime, curGPStimenull));
//Create file
if (isExternalStorageWritable()){
GPSwriter = new FileWriter(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).toString() + "/" + myfolder,"Location.csv"));
try{
GPSwriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//Scan Media to see the files -> When I scan "f" I can see the folder at least, when I just scan the file, I cannot see anything at all //
MediaScannerConnection.scanFile(this, new String[]{f.toString()}, null, null);```
答案 0 :(得分:0)
我已经解决了这个问题!
我想问题是,文件是在受保护的类中创建的。我将其移至程序的开头,现在它可以工作了:)
最好!