简体   繁体   English

Android Studio-从Windows资源管理器和Android文件管理器访问/ storage / emulated / 0

[英]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.

相关问题 Android Studio,/ storage / emulated / 0不存在 - Android studio, /storage/emulated/0 not exist 如何在 Android Studio 中以编程方式将 apk 文件从 root/data/app/ 移动到 storage/emulated/0 - How to move an apk file from root/data/app/ to storage/emulated/0 programmatically in Android Studio Android 应用程序在 windows 资源管理器中不可见,警告 ls: /storage/emulated/: 权限被拒绝 - Android app not visible in windows explorer, warning ls: /storage/emulated/: Permission denied Android设备上的file:/// storage / emulated / 0路径 - file:///storage/emulated/0 path on android device Android - 无法打开内容:file:///storage/emulated/0 - Android - Unable to open content: file:///storage/emulated/0 模拟外部存储android - emulated external storage android FileNotFoundException:/ storage / emulated / 0 / Android - FileNotFoundException: /storage/emulated/0/Android Android Studio 中的文件资源管理器 - File Explorer in Android Studio Android-避免保存到存储/仿真/ 0 - Android - Avoid saving to storage/emulated/0 java.io.FileNotFoundException:/storage/emulated/0/Android/data/MyApplication/MyFile.ics。 (没有这样的文件或目录)/ Android Studio / Ical4j - java.io.FileNotFoundException: /storage/emulated/0/Android/data/MyApplication/MyFile.ics. (No such file or directory) / Android Studio / Ical4j
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM