写入存储,而不是模拟在Nexus 7 [英] writing to storage instead of emulated on nexus 7

查看:212
本文介绍了写入存储,而不是模拟在Nexus 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code,写东西,用这个code到文件

In my code, write stuff to file using this code

//the path  
String fileName = Environment.getExternalStoragePublicDirectory(fileName) + File.separator+"Foo"+File.separator;
File dir = new File(fileName);
//the file
fileName += "bar"
File file = new File(fileName);
try {
file.createNewFile();   
} catch (IOException e) {
    //do nothing, for now
}
return;

这将导致与文件写入 /存储/模拟/ 0 / ,而不是 /存储/ sdcard0 。我有这样的问题是,我没有看到 /存储/模拟/ 0 / 当我将设备连接到我的机器(Ubuntu的13.10)。

This results with the file being written /storage/emulated/0/ and not to /storage/sdcard0. The problem I have with this is that I dont see /storage/emulated/0/ when I connect the device to my machine (Ubuntu 13.10).

推荐答案

在将设备连接到[你]机,你没有得到设备的根目录下。你将有机会获得外部存储。

When you "connect the device to [your] machine", you do not get the root directory of the device. You will have access to external storage.

此外,<一个href=\"https://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29\"相对=nofollow> getExternalStoragePublicDirectory()作为参数的不采取随机值。使用类似 Environment.DIRECTORY_DOWNLOADS

例如,这里是我在Ubuntu 13.10看到,当我插上的Nexus 7(2013):

For example, here is what I see on Ubuntu 13.10 when I plug in a Nexus 7 (2013):

当我进入内部存储,我看到的:

When I go into "Internal storage", I see:

下面是内容的的/ mnt /壳/模拟/ 0 / ,在DDMS查看:

Here is the contents of /mnt/shell/emulated/0/, as viewed in DDMS:

您会发现,对于内部存储列出该目录是相同的,因为它是的/ mnt /壳/模拟/ 0 / 。这是因为的它们是同一个目录

You will notice that the directory listing for "Internal storage" is the same as it is for /mnt/shell/emulated/0/. That is because they are the same directory.

对于主要用户帐户, Environment.getExternalStorageDirectory()指向一个点,在DDMS中查看时,最高显示为的/ mnt /外壳/模拟/ 0 / ,并通过MTP,显示为内部存储。(虽然后者是的Nexus 7的名字 - 它可能会因设备而异)

For the primary user account, Environment.getExternalStorageDirectory() points to a spot that, when viewed in DDMS, shows up as /mnt/shell/emulated/0/ and, via MTP, shows up as "Internal storage" (though the latter is the Nexus 7's name for it -- it may vary by device).

另外请注意,MTP可能不会显示一切,这是在的/ mnt /壳/模拟/ 0 / ,因为MTP是真的 MediaStore驱动,而不是一切都可能被尚未索引。如果你写的文件到外部存储,使用 MediaScannerConnection SCANFILE()来确保MTP连接的设备的结束知道它们。

Also note that MTP may not show everything that is in /mnt/shell/emulated/0/, because MTP is really driven by MediaStore, and not everything may have been indexed yet. If you write files to external storage, use MediaScannerConnection and scanFile() to ensure that the device's end of the MTP connection knows about them.

和我的混内部存储/外部存储术语道歉。我只是通过写作博客文章意甲了在试着解释这一切。

And I apologize for the mixed "internal storage" / "external storage" terminology. I just got through writing a blog post series trying to explain all of that.

这篇关于写入存储,而不是模拟在Nexus 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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