模拟器与三星设备SD卡存储 [英] Emulator vs Samsung device SD Card Storage

查看:63
本文介绍了模拟器与三星设备SD卡存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

三星设备是具有Android 7.0 API 24的T810,并且具有SD卡,我们创建的其他应用程序已将该SD卡正确写入SD卡上的SQLite DB.可悲的是,我们不知道这是否是在Android 7.0更新之前.到目前为止,我们无法使用下面发布的代码写入SD卡.在运行API 26的仿真器上,设备文件浏览器正在显示此信息 数据库仿真器 /mnt/user/0/primary/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord 贮存 /storage/emulated/0/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord SD卡模拟器 /sdcard/Android/data/com.androidstackoverflow.onepass/files/Documents/PassWord

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;
}

我们需要帮助的问题是这是三星设备问题还是模拟器不是真实信息? 权限设置为READ和WRITE 我们甚至尝试过硬编码该路径.看了很多关于此主题的SO帖子.文件夹Documents/DB Name的创建没有问题

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

推荐答案

首先,产生此答案的信息由@CommonsWare提供 它张贴在这里,以便其他人无法学习,因此我可以获取积分 问题是如何管理三星平板电脑上的存储位置 最重要的是,您了解测试是否已将SD卡安装在仿真器上的操作.下面是我非常奇怪的代码,用于测试是否已安装SD卡.然后是修改后的代码,可让您管理存储位置

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;
}

这篇关于模拟器与三星设备SD卡存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆