[英]Android Studio - Acces to /storage/emulated/0 from windows explorer and android file manager
I a newbie in android development. 我是android开发的新手。 I sure that many people have same issue. 我确定很多人都有同样的问题。 I ve a Galaxy S7 phone without SD Card. 我有一个没有SD卡的Galaxy S7手机 。 So no external storage. 因此没有外部存储。 But i want create file with my app which have to be access from windows explorer to export it. 但是我想用我的应用程序创建文件,必须从Windows资源管理器访问该文件才能将其导出。
Note : debbug in USB mode - No virtual device 注意:USB模式下的调试-无虚拟设备
Of course in my manifest file i ve setted those 2 permissions : 当然,在清单文件中,我已经设置了这两个权限:
android.permission.WRITE_INTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
To be sure i ve created a file i use this write method and the following read method : 为确保已创建文件,我使用此write方法和以下read方法:
File root = this.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
File customFolder = new File(root.getAbsolutePath() + "/CustomFolder");
customFolder.mkdirs();
file = new File(customFolder, "myData.txt");
// Must catch FileNotFoundException and IOException
try {
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println("Howdy do to you,");
pw.println("and the horse you rode in on.");
pw.flush();
pw.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i(TAG, "File not found");
} catch (IOException e) {
e.printStackTrace();
Log.i(TAG, "I/O exception");
}
To read myData.txt 读取myData.txt
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while (true) {
line= br.readLine();
if (line== null) break;
tv.append("\n" + " " + line);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
So all method are OK, but when i browse my files system to get the created file myData.txt, I can't find it !! 所以所有方法都可以,但是当我浏览我的文件系统以获取创建的文件myData.txt时,我找不到它!
Most of the apps we install have their own folder on the root, like Snapchat, Whatsapp etc etc 我们安装的大多数应用在根目录上都有自己的文件夹,例如Snapchat,Whatsapp等
I d like to make the same thing, what is the way to write file in: 我想做同样的事情,用什么方法写文件:
ROOT --> MyApplicationName --> CustomFolder 根目录-> MyApplicationName-> CustomFolder
Thanks for your help :) 谢谢你的帮助 :)
I finally found a solution adding a MediaScannerConnection.scanFile() method. 我终于找到了添加MediaScannerConnection.scanFile()方法的解决方案。
MediaScannerConnection.scanFile(getApplicationContext(),new String[]{file.getAbsolutePath()},null,new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
// Do something here if you want
}});
But this solution don't totally fit me, because the storage folder is : 但是此解决方案并不完全适合我,因为存储文件夹为:
Android/data/donain_name/files/Documents/CustomFolder 安卓/数据/ donain_name /文件/文件/ CustomFolder
I'd like to have same result like whatsapp application which can have a folder in the internal storage root. 我想要类似whatsapp应用程序的结果,该应用程序可以在内部存储根目录中有一个文件夹。
The result i want is : MyApplication/CustomeFolder 我想要的结果是: MyApplication / CustomeFolder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.