Android file with poor permissions

When I write the file to the SD card, it writes the file with permissions -rw-rw ---- and the owner with root privileges. I followed android recommendations for file permissions, but wrote nothing about writing the file as root. I need to open this file using the Android file manager, but I do not have privileges since I am not rooted. This is the code to output the file:

 File file = getExternalStorageDirectory();

 File sim = new File(file, "Driving Sim App/");
 sim.getParentFile().mkdirs();
 sim = new File(sim, name+".csv");

 try {
     BufferedWriter bor = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sim)));
     bor.write("This is a test");
     bor.close();
 } catch (FileNotFoundException e) {
     e.printStackTrace();
     return;
 } catch (IOException e) {
     e.printStackTrace();
 }

I also have this in my manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Any help would be appreciated, thanks!

+4
source share
2 answers

You might want to try: File file = Environment.getExternalStorageDirectory();

0
source

. -, , . , . :

parent_dir//child_dir.csv
parent_dirchild_dir.csv
parent_dir/child_dir/.csv
parent_dir/child_dir.csv/

, :

parent_dir/child_dir.csv

, , - Android. , Android, , (, ).

, MediaScannerConnection.

MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null,
        new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);
            }
});

^^ , - : SD- MEDIA_MOUNTED

0

All Articles