简体   繁体   中英

Emulator vs Samsung device SD Card Storage

The Samsung Device is a T810 with Android 7.0 API 24 and has a SD Card that other apps we have created have written to the SQLite DB on the SD Card with no issues. Sad to say we are not sure if this was before the Android 7.0 update. As of now we can not use code posted below to write to the SD Card. On the Emulator running API 26 the device file explorer is showing this information Database Emulator /mnt/user/0/primary/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord Storage /storage/emulated/0/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord SD Card Emulator /sdcard/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord

    public String getThePath(){

    File removable = ContextCompat.getExternalFilesDirs(this,null)[0];
    if (removable.exists() && removable.canRead() && removable.canWrite()) {
        THE_PATH = String.valueOf(removable);
        THE_PATH = THE_PATH + "/Documents/";
    }else {
        Toast.makeText(getApplicationContext(),"NO SD CARD", Toast.LENGTH_LONG).show();
    }
    return THE_PATH;
}

The question we would like help with is this a Samsung device issue or is the emulator not truthful information? Permissions are set both READ and WRITE We have even tried to hard code the path. Looked at numerous SO posts on this subject. The folder Documents/DB Name gets created with no issues

First the information to produce this answer was provided by @CommonsWare It is posted here so others can learn not so I can grab points The issue was how to manage the storage location on a Samsung Tablet It is most important that you understand testing if the SD Card is mounted on the Emulator is not going to work Below is my very odd code to test if the SD Card was mounted or not. Then the revised code that lets you manage the storage location

    File fi = new File("storage/");
    File[] lst = fi.listFiles();//
    String top = String.valueOf(lst[1]);
    String bot = String.valueOf(lst[0]);

    if(bot.contains("-")){
        STORAGE_LOCATION = 1;
    }
    if(top.contains("storage/enc_emulated")){
        STORAGE_LOCATION = 0;
    }
    public String getThePath(){

    File removable = ContextCompat.getExternalFilesDirs(this,null) 
   [STORAGE_LOCATION];

    if(STORAGE_LOCATION == 1){
        THE_PATH = String.valueOf(removable);
        THE_PATH = THE_PATH + "/Documents/";
    }
    if(STORAGE_LOCATION == 0){
        THE_PATH = String.valueOf(removable);
        THE_PATH = THE_PATH + "/INTERNAL/";
        Toast.makeText(getApplicationContext(),"NO SD CARD", 
    Toast.LENGTH_LONG).show();
    }
        return THE_PATH;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM