我想下载一些文件,并将它们保存到手机/标签的内部存储。试图在三星Galaxy Note 2和Galaxt选项卡10.1。当我使用 /存储/ sdcard0 /
对他们的code成功运行,但是当我使用 Galaxy Nexus的3
在code失败。
我想获得phoe或标签的内部存储的绝对路径绝对路径
。
是否有可能,如果是的话怎么办?
解决方案当我使用/存储/ sdcard0 /对他们的code成功运行,但是当我使用Galaxy Nexus的3 code失败。
/存储/ sdcard0 /
不是内部存储。它是外部存储
(顺便说一句,因为没有命名为Galaxy Nexus的3的设备,我假设你只是意味着Galaxy Nexus的)
要找到的的内部的存储你的应用程序,使用 getFilesDir()
,呼吁任何上下文(比如你的
活动
,获得文件
对象。
要在获得一个位置的外部的存储独特的为您的应用程序,使用 getExternalFilesDir()
,呼吁任何上下文
(比如你的活动
,获得文件
对象。
要获得的标准的位置的外部的存储常用类型的文件(如电影),使用 getExternalStoragePublicDirectory()
在环保
。
要获得的根的外部的存储,使用 getExternalStorageDirectory()
在环境的
。然而,这被认为是草率的编程时下,因为它鼓励开发人员只是把文件放在任意位置。
I want to download some files and save them into the internal storage of the phone/tab. Tried on Samsung Galaxy Note 2 and Galaxt Tab 10.1. When I use /storage/sdcard0/
on them the code runs successfully but when I use Galaxy Nexus 3
the code fails.
I want to get absolute path of the phoe or tab's internal storage' Absolute Path
.
Does it possible, if so how?
解决方案When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.
/storage/sdcard0/
is not internal storage. It is external storage.
(BTW, since there is no device named "Galaxy Nexus 3", I am assuming that you simply meant "Galaxy Nexus")
To find locations on internal storage for your app, use getFilesDir()
, called on any Context
(such as your Activity
, to get a File
object.
To get a location on external storage unique for your app, use getExternalFilesDir()
, called on any Context
(such as your Activity
, to get a File
object.
To get a standard location on external storage for common types of files (e.g., movies), use getExternalStoragePublicDirectory()
on Environment
.
To get the root of external storage, use getExternalStorageDirectory()
on Environment
. This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations.
相关推荐
最新文章