`/存储/模拟/遗留/``VS /存储/模拟/ 0 /``VS数据/数据​​/对myApp“ [英] `/storage/emulated/legacy/` vs `/storage/emulated/0/` vs `data/data/myApp'

查看:157
本文介绍了`/存储/模拟/遗留/``VS /存储/模拟/ 0 /``VS数据/数据​​/对myApp“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要救我的应用程序的镜像文件

I want to save in my app an imageFile

我要栽跟头的Google+应用程序来使用它。

I want "Google+ cropper app" to use it.

但后来打开另一个形象。

But the later opens another image.

我想这是权限问题。

在我的code我在这里保存:

In my code i save here:

这是外部存储? Environment.getExternalStorageDirectory()getAbsolutePath()返回: /storage/emulated/0/myApp/file1.tmp

Is this external storage? Environment.getExternalStorageDirectory().getAbsolutePath() which returns: /storage/emulated/0/myApp/file1.tmp

使用亚行外壳是看文件实际上是保存在: /storage/emulated/legacy/myApp/file1.tmp

using adb shell is see the file is actually saved in: /storage/emulated/legacy/myApp/file1.tmp

为什么不一样呢?

我要使用这个地方呢? 这是外部存储?

should i use this place instead? Is this external storage?

getAppContext()getFilesDir()的getParent()返回:`数据/数据​​/对myApp

getAppContext().getFilesDir().getParent() which returns: `data/data/myApp'

推荐答案

在历史上内部和外部存储之间的差异情况如下...

Historically the difference between internal and external storage was as follows...

内部:用于分配专用存储的每个应用程序的Andr​​oid设备的内部RAM。分配的存储保护,任何其他应用程序prevent访问(上植根设备除外)。

Internal: The internal RAM of an Android device used to allocate private storage for each app. The storage allocated is protected to prevent access by any other app (except on rooted devices).

外部:在很多情况下,SD卡,没有安全限制,也就是说,所有的应用程序都可以访问的外部存储器的所有领域

External: In many cases an SD card with no security restrictions, i.e., all apps can access all areas of "external" storage.

由于机器人的新版本也随之而新设备有越来越多的内部RAM,内部和外部是变模糊之差。例如我的Nexus 7没有一个SD卡插槽。

As new versions of Android have come along and new devices have increasingly more internal RAM, the difference between internal and external is becoming blurred. For example my Nexus 7 doesn't have an SD card slot.

在设备的情况下,没有真正的外部存储设备,它仍然需要为Android提供一个模拟的外部存储,以保持与旧应用程序兼容。换言之,RAM是物理上的内部(不可拆卸的),但它的一个部分被分隔和​​Android文件系统API对待该分区为外部和世界可读

In the case of devices without true external storage, it's still necessary for Android to provide an emulated external storage in order to remain compatible with older apps. In other words the RAM is physically internal (non-removable) but a section of it is partitioned and the Android file-system APIs treat that partition as being "external" and world-readable.

至于你看到的外部存储的路径,如...

As for the paths you see for external storage such as...

/storage/emulated/0/myApp/file1.tmp
/storage/emulated/legacy/myApp/file1.tmp

...的一个或另一个的那些(可能两者)是一个重定向或虚拟路径到仿真外部目录和文件的同一部分。

...one or other of those (possibly both) is a redirection or "virtual" path to the same part of the emulated external directory and file.

这就是为什么它是必不可少总是使用正确的API调用才能访问的文件和目录,而不是假设一个硬codeD的路径,因为它很可能从设备而异。

This is why it is essential to always use the correct API call to get access to files and directories rather than assuming a hard-coded path as it may well vary from device to device.

如果您使用 Environment.getExternalStorageDirectory(),你可以相信,任何其他应用程序,它做同样将能够获得访问你那里创建任何文件。

If you use Environment.getExternalStorageDirectory(), you can be confident that any other app which does the same will be able to get access to any files you create there.

如果您使用 getFilesDir(),那么你正在访问分配私下向您的应用程序和访问的内部存储的根只能到你的应用程序(虽然,正如我所说一个根深蒂固的手机可以访问私有/内部存储)。

If you use getFilesDir() then you are accessing the root of the internal storage allocated privately to your app and accessible only to your app (although, as I mentioned a rooted phone can access private / internal storage).

这篇关于`/存储/模拟/遗留/``VS /存储/模拟/ 0 /``VS数据/数据​​/对myApp“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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