0
public void exportDatabse(String databaseName) {

        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
           if (sd.canWrite()) {
                String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
                String backupDBPath ="//database.sql";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);

                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();

                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                    Log.i(TAG,"coping database sucessfull");
                }
            }
        } catch (Exception e) {
        Log.i(TAG,"exception! "+ e.getMessage());
        }
    }

While debugging the sd file location File sd = Environment.getExternalStorageDirectory(); is

/storage/emulated/0

enter image description here

The copied file isn't visible in my SDcard. Moreover, I know the location of the sd file is incorrect. How can I get the database.sql file? UPDATE

enter image description here

Expiredmind
  • 788
  • 1
  • 8
  • 29
  • 1
    [External storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html) is not [removable storage](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html). You have a lot of duplicated `/` values that should be fixed. And your copy will not be visible to most apps (and desktop operating systems), unless [you get that copy indexed by the `MediaStore`](https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl). – CommonsWare Dec 28 '16 at 12:23

1 Answers1

2

The value returned by Environment.getExternalStorageDirectory is correct and there is nothing wrong with it.

The problem here is that the Android Device Monitor doesn't directly support symlinks (symbolic links). You should manually follow/expand them in the File Explorer.

So in your case you need to expand the storage folder followed by the emulated and 0 folder.

If that doesn't work you might want to try to expand the storage folder followed by the self and primary folder.

TLDR: manually follow/expand the paths in the info column.

Edit: Try expanding the folders marked in yellow.

Android Device Monitor File Explorer

Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
  • the files on my destination folders are in folder 6314-6720 so i need to create file on that path? did you have any expirience how to do it? – Expiredmind Dec 28 '16 at 11:53
  • You don't need to create anything (your code seems fine), just expand the correct folders and follow the symlinks. Also make sure you code doesn't fail (check the logcat), you also need permission to write to the external storage: WRITE_EXTERNAL_STORAGE. – Rolf ツ Dec 28 '16 at 12:02
  • in Android Device Monitor? The storage/emulate folder is empty or i dont have acces to it – Expiredmind Dec 28 '16 at 12:08
  • I expand it and my 6314-6720 are contatin my sd card and self contatin empty primary folder (screens in question) but both doesnt contatin database.sql file – Expiredmind Dec 28 '16 at 12:30
  • Check if your code successfully executes (no exceptions are thrown). I also would like to mention @CommonsWare, his comment contains some good information. – Rolf ツ Dec 28 '16 at 12:36
  • Code does not throw any exception, I checked the @CommonsWare, thanks – Expiredmind Dec 28 '16 at 12:39