【问题标题】:what's the directory of external storage on nexus LGNexus LG 上的外部存储目录是什么
【发布时间】:2014-02-24 02:56:25
【问题描述】:

以下代码 sn-p 正在尝试存储 Gesture 对象。

private Gesture mGesture;
private GestureLibrary store;
store.addGesture("test", mGesture);
store.save();

我想知道mGesture 存储在哪里?

紧跟上面的代码,作者给出如下代码:

final String path = new File(Environment.getExternalStorageDirectory(),
                    "gestures").getAbsolutePath();
Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();

所以我猜mGesture 存储在path 指示的某个地方。 但我不知道什么是路径。我试过调试。它给了我类似的东西:“storage/emulated/0/gestures/”。但是我在我的设备上找不到这个目录。 顺便说一句,我的设备是nexus 4

【问题讨论】:

    标签: android android-external-storage


    【解决方案1】:

    Nexus 设备没有 SD 插槽。他们假装内部驱动器上的某个地方是 SD 卡。但是该函数返回的确切路径确实存在于您的设备上,否则您无法为其创建文件。

    顺便说一句,不要依赖于返回的值在设备之间是相同的。不是。

    【讨论】:

    • 对于GestureLibrary的方法save,似乎没有指定保存目标对象的“位置”。 save这个方法怎么知道在哪里保存。
    【解决方案2】:

    是的,同意 gabe,这只是一个建议,但您可以使用 if 和 else 以及 mkdirs 来检查目录或文件夹是否存在,如果它不存在,它将在指定位置创建一个新文件夹。

    【讨论】:

      【解决方案3】:

      由于 Nexus 4 没有外部 SD,(我现在正在使用的 Nexus 5 也是如此),它的操作系统会暂时模拟 SD。因此,调用Environment.getExternalStorageDirectory() 会返回以下路径:tempDirPath:/storage/emulated/0/,但您稍后可以通过/storage/emulated/legacy 访问它。

      尝试通过adb shell访问它,这个legacy文件夹将存储模拟的外部SD的内容。

      【讨论】:

        猜你喜欢
        • 2016-07-06
        • 2017-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-30
        • 2013-06-06
        • 1970-01-01
        • 2012-02-07
        相关资源
        最近更新 更多